Docker
Installing Docker
brew cask install docker
Installing Kitematic
You can install Kitematic
from your terminal running: brew cask install kitematic
Create a Private Docker Registry
Installing Package for Added Security
We'll install the apache2-utils
package which contains the htpasswd
utility that can easily generate password hashes Nginx can understand:
Installing and Configuring the Docker Registry
Docker Compose allows you to write one .yml
configuration file for the configuration for each container
First create a folder where our files for this tutorial will live and some of the subfolders we'll need:
Using your favorite text editor, create a docker-compose.yml
file:
Add the following contents to the file:
Docker registry's data all gets stored in ~/docker-registry/data
on our local machine.
Setting Up an Nginx Container
Let's get to work on fixing these security issues. The first step is to set up a copy of Nginx inside another Docker container and link it up to our Docker registry container.
Let's start by creating a directory to store our Nginx configuration:
Now, re-open your docker-compose.yml
file in the ~/docker-registry
directory:
Add a service on top of the registry service:
Your full docker-compose.yml
file should now look like this:
We need to configure Nginx before this will work though, so let's create a new Nginx configuration file.
Create a registry.conf
file:
Copy the following into the file:
Save and exit the file.
Now you can install Nginx and start up the two Docker containers all with one command:
First, make an HTTP request directly to the Docker registry:
As of this writing Docker returns an empty json object, so you should see:
Now send an HTTP request to the Nginx port:
You should see the same output:
Setting Up Authentication
Set up HTTP authentication so that we can control who has access to our Docker registry. To do that we'll create an authentication file in Apache format (Nginx can read it too) via the htpasswd
utility we installed earlier and add users to it.
Create the first user as follows, replacing USERNAME with the username you want to use:
Create a new password for this user when prompted.
If you want to add more users in the future, just re-run the above command without the -c
option (the c
is for create):
At this point we have a registry.password
file with our users set up and a Docker registry available. You can take a peek at the file at any point if you want to view your users (and remove users if you want to revoke access).
Next, we need to tell Nginx to use that authentication file.
Open up ~/docker-registry/nginx/registry.conf
in your favorite text editor:
Uncomment the two lines that start with auth_basic
as well as the line that starts with add_header
by removing the #
character at the beginning
of the lines. It should then look like this:~/docker-registry/nginx/registry.conf
We've now told Nginx to enable HTTP basic authentication for all requests that get proxied to the Docker registry and told it to use the password file we just created.
Let's bring our containers back up to see if authentication is working:
Repeat the previous curl test:
You should get a message complaining about being unauthorized:
Now try adding the username and password you created earlier to the curl
request:
You should get the same output you were getting before — the empty json object {}
. You should also see the same registry_
output in the docker-compose
terminal.
Go ahead and use CTRL-C
in the docker-compose
terminal to shut down the Docker containers.
Starting Docker Registry as a Service
Let's go ahead and start it up to make sure everything is in order:
If everything went well you should have your Docker Registry up and running.
Publish to your Private Docker Registry
From your client machine, create a small empty image to push to our new registry.
After it finishes downloading you'll be inside a Docker prompt. Let's make a quick change to the filesystem by creating a file called SUCCESS
:
Exit out of the Docker container:
Commit the change:
Log in to your registry:
Enter the username and password you set up earlier, now let's tag our image to our private registry:
Note that you are using the local name of the image first, then the tag you want to add to it. The tag does not use https://
, just the domain, port, and image name.
Now we can push that image to our registry. This time we're using the tag name only:
Pull from Your Docker Registry
To make sure everything worked, let's go back to our original server (where you installed the Docker registry) and pull the image we just pushed from the client. You could also test this from a third server.
If Docker is not installed on your test pull server, go back and follow the installation instructions (and if it's a third server, the SSL instructions) from Step 6.
Log in with the username and password you set up previously.
And now pull the image. You want just the "tag" image name, which includes the domain name, port, and image name (but not https://
):
Docker Registry Manager
We can install a useful manager like this:
We just need to clone the repo and edit the registry.yml
file, then run docker-compose up -d
and go to http://localhost:8080
Last updated