Tuesday, March 10, 2015

Setting up a Continuous Integration Environment with Jenkins and Docker PART 5, Using your Docker Registry

In this the fifth part of my tutorial on setting up a private Docker Registry, I will discuss how to use the registry.  

Publishing 

On the client server, create a small empty image to push to the new registry.


> docker run -t -i centos /bin/bash
Unable to find image 'centos' locally
Pulling repository centos
8efe422e6104: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete

Status: Downloaded newer image for centos:latest

After it finishes downloading you'll be at a Docker prompt. Lets make a quick change to the filesystem: 

[root@4b1b63dfe9e6 /]# touch /tmp/junk

Exit out of the Docker container.

[root@4b1b63dfe9e6 /]# exit


The command docker images command has three crucial pieces of information.

  • What repository they came from.
  • The tags for each image.
  • The image ID of each image.
Lets look for my image 4b1b63dfe9e6. 
> docker images
docker images
REPOSITORY     TAG      IMAGE ID        CREATED             VIRTUAL SIZE
centos         7        8efe422e6104    3 weeks ago         224 MB
centos         centos7  8efe422e6104    3 weeks ago         224 MB

centos         latest   8efe422e6104    3 weeks ago         224 MB


It won't be listed because I still need to commit the change. 
Lets look for my latest created container ( ps -lq ).

>  docker ps -lq
4b1b63dfe9e6

Good I didn't lose it.

Commit the change: 

> docker commit 4b1b63dfe9e6 my-test-image
eb2889afbbaff0e9d20760fd49be14a73e386709c69a20c6f34ed4b07fa3acdf

Lets run the docker images command again:

> docker images
REPOSITORY      TAG      IMAGE ID      CREATED             VIRTUAL SIZE
my-test-image   latest   eb2889afbbaf  30 seconds ago      224 MB
centos          centos7  8efe422e6104  3 weeks ago         224 MB
centos          latest   8efe422e6104  3 weeks ago         224 MB

centos          7        8efe422e6104  3 weeks ago         224 MB

Ah there it is. However this image only exists locally, let's push it to the new registry.
First, log in to the registry with Docker. 

> docker login https://myserver.com:8080
Username (pete):
Login Succeeded

To use our local registry and find our image again we have to tag the image with the private registry's location in order to push to it. 

> docker tag my-test-image myserver.com:8080/my-test-image

Note that you are using the local name of the image first, then the tag you want to add to it. The tag is not using https://, just the domain, port and image name. 

Now we can push that image to our registry. This time using the tag name only:

> docker push myserver.com:8080/my-test-image
The push refers to a repository [myserver.com:8080/my-test-image](len: 1)
Sending image list
Pushing repository myserver.com:8080/my-test-image (1 tags)
511136ea3c5a: Pushing 1.536 kB/1.536 kB
2015/01/26 15:34:05 

Pulling from the Docker Registry.

It appears that we successfully pushed our test image up to the Docker Registry.  Lets log in as a different user, then connect to the Docker Registry as that new user.

> docker login https://myserver.com:8080
Username (jsmith):
Login Succeeded

> docker images

REPOSITORY        TAG         IMAGE ID       CREATED       VIRTUAL SIZE
my-test-image     latest      eb2889afbbaf   3 days ago     224 MB
myserver.com:8080/my-test-image   latest     eb2889afbbaf   3 days ago          224 MB
centos           7            8efe422e6104  3 weeks ago     224 MB
centos           centos7      8efe422e6104  3 weeks ago     224 MB
centos           latest       8efe422e6104  3 weeks ago     224 MB