Wednesday, January 29, 2014

Running your own docker registry on Fedora or RHEL/CentOS 6

This isn't going to be a very wordy post, it's just the process I used to setup a local docker registry for testing purposes. This can be done with either Fedora or RHEL/CentOS 6 with EPEL. I'm mostly just writing this process down because I had to look up the info from more than one location and figured I should write it down in one place so I remember next time I try to do it and hopefully someone else might find it useful.

Before we start, if you're running RHEL or CentOS 6 you're going to need EPEL6 installed from here.

First, install the packages:

yum -y install docker-io docker-registry

Next we need to start up the services (I know I'm not doing the native systemd/systemctl commands here but this way it works on both Fedora and RHEL/CentOS so I went that route)

service docker start
service docker-registry start
service redis start

You can chkconfig on or systemctl enable them if you so choose and they will start persistently on reboots

Next up, just as an example lets go ahead and pull a docker image. (Note: you either need to do this as root or as an user that's in been added to the docker group)

# docker pull centos
Pulling repository centos
539c0211cd76: Download complete

docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos 6.4 539c0211cd76 10 months ago 300.6 MB
centos latest 539c0211cd76 10 months ago 300.6 MB


Now we can run a centos image as a container

# docker run -t -i centos /bin/bash
bash-4.1#

You are able to disconnect from it but still leave it running with Ctrl-p+Ctrl-q which you will then see it in the running docker list.

# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
ab0e4ba814ab centos:6.4 /bin/bash 50 minutes ago Exit 0
angry_euclide

Next up we need to commit this with our registry (this would potentially be an image you made changes to from the base image, or otherwise).

# docker commit ab0e4ba814ab localhost.localdomain:5000/centos_local
6c82b393337351db8c63b807efc6700934eecc364357a26a472a899f63d4fc09
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
ab0e4ba814ab centos:6.4 /bin/bash About an hour ago Up 25 minutes
angry_euclide


Once that it done we can push to our registry.

# docker push localhost.localdomain:5000/centos_local
The push refers to a repository [localhost.localdomain:5000/centos_local] (len: 1)
Sending image list
Pushing repository localhost.localdomain:5000/centos_local (1 tags)
539c0211cd76: Pushing [=================================================> ] 310.8 MB/310.9 MB 0
6c82b3933373: Pushing [=================================================> ] 288.1 MB/288.2 MB 0
Pushing tags for rev [6c82b3933373] on {http://localhost.localdomain:5000/v1/repositories/centos_local/tags/lates
t}


Alternatively we can build and tag from a Dockerfile.

(Because I can't figure out how to make blogger show a heredoc properly I'm just using an echo with a redirect ... it works so I'm moving on)

# echo 'FROM centos
MAINTAINER "Adam Miller"

RUN yum -y update
RUN yum -y install httpd
EXPOSE 80

CMD /usr/sbin/apachectl -D FOREGROUND' > Dockerfile


# docker build -t localhost:5000/centos_httpd .
Uploading context 51.2 kB
Step 1 : FROM centos

---> 539c0211cd76
Step 2 : MAINTAINER "Adam Miller"
---> Running in 7fde3245be29
---> 89f2c637957f
Step 3 : RUN yum -y update
---> Running in b6c6bd22fcb5
Loaded plugins: fastestmirror
Setting up Update Process
Resolving Dependencies
--> Running transaction check


************************************************************************

******** NOTE: Lots of yum output omitted here for brevity *************
************************************************************************

Transaction Summary
======================================================================
Install 6 Package(s)
Upgrade 57 Package(s)

Total download size: 50 M

Complete!
---> dc4fad6ccf28
Step 4 : RUN yum -y install httpd
---> Running in 2bc296aed371
************************************************************************

********** NOTE: Some yum output omitted here for brevity **************
************************************************************************

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.2.15-29.el6.centos base 821 k
Installing for dependencies:
apr x86_64 1.3.9-5.el6_2 base 123 k
apr-util x86_64 1.3.9-3.el6_0.1 base 87 k
apr-util-ldap x86_64 1.3.9-3.el6_0.1 base 15 k
httpd-tools x86_64 2.2.15-29.el6.centos base 73 k
mailcap noarch 2.1.31-2.el6 base 27 k
redhat-logos noarch 60.0.14-12.el6.centos base 15 M

Transaction Summary
================================================================================
Install 7 Package(s)

Total download size: 16 M
Installed size: 19 M


Complete!
---> d1fcb707794d
Step 5 : EXPOSE 80
---> Running in 3e5baa8bf52f
---> 50f9343d8a7d
Step 6 : CMD /usr/sbin/apachectl -D FOREGROUND
---> Running in 916de09d72bb
---> 0d908165e418
Successfully built 0d908165e418

# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
localhost:5000/centos_httpd latest 0d908165e418 11 minutes ago 628.8 MB
localhost.localdomain:5000/centos_local latest 6c82b3933373 2 hours ago 594.5 MB
centos 6.4 539c0211cd76 10 months ago 300.6 MB
centos latest 539c0211cd76 10 months ago 300.6 MB

# docker tag 0d908165e418 localhost:5000/centos_httpd
# docker push localhost:5000/centos_httpd
The push refers to a repository [localhost:5000/centos_httpd] (len: 1)
Sending image list
Pushing repository localhost:5000/centos_httpd (1 tags)
539c0211cd76: Image already pushed, skipping
89f2c637957f: Pushing [=====> ] 1.024 kB/10.24 kB 5s
dc4fad6ccf28: Pushing [=================================================> ] 288.2 MB/288.3 MB 0
d1fcb707794d: Pushing [=================================================> ] 34.76 MB/34.96 MB 0
50f9343d8a7d: Pushing [=====> ] 1.024 kB/10.24 kB 1s
0d908165e418: Pushing [=====> ] 1.024 kB/10.24 kB 1s
Pushing tags for rev [0d908165e418] on {http://localhost:5000/v1/repositories/centos_httpd/tags/latest}


Now we can pull one of the images we've created from the registry.
# docker pull localhost:5000/centos_httpd
Pulling repository localhost:5000/centos_httpd
89f2c637957f: Download complete
dc4fad6ccf28: Download complete
d1fcb707794d: Download complete
0d908165e418: Download complete
50f9343d8a7d: Download complete
539c0211cd76: Download complete


That's about it, this of course is just setup for use on the localhost mostly just as an example. The docker registry can be configured from /etc/docker-registry.yml

For more information, here's a list of resources about docker registry and index:
http://blog.thoward37.me/articles/where-are-docker-images-stored/
http://docs.docker.io/en/latest/api/registry_index_spec/
http://blog.docker.io/2013/07/how-to-use-your-own-registry/
http://kencochrane.net/blog/2013/08/the-docker-guidebook/#part-6-using-a-private-registry
https://github.com/dotcloud/docker-registry

4 comments:

Unknown said...

I have followed your instructions and I am able to create a local registry and push/pull images in to the local registry. While I am able to do everything from the same machine, if I try to push/pull the images from another docker machine to this registry, I am getting an error.

Host-A/Docker/Docker-Registry/Redis
1. Created image using ":5000/ format
docker tag "dhcp-corp-233.sc-cig-eng.tst:5000/sles"
2. Push/Pull the image in to local repository. Works Great!
docker push dhcp-corp-233.sc-cig-eng.tst:5000/sles
docker pull dhcp-corp-233.sc-cig-eng.tst:5000/sles

Host-B/Docker
I am not able to pull the image using "docker pull dhcp-corp-233.sc-cig-eng.tst:5000/sles"
from Host-B

Am I missing anything? How can I host a machine in my network as docker registry and access the images from other connected hosts?

tcarlson said...

How do we change where the images are stored? Instead of storing under the /var/lib/docker-registry/... we want to store them on a mounted NAS drive.

Unknown said...

Hi , nice post , I am able to run my private registry on "localhost:5000/v1", but not aware how to list all the images via browser. Tried using "http://mydocker.repo:8080/v1/search" but it doesnt list the images. Can you please help how to list all the images present in docker-registry.

thanks,
Yash

Anonymous said...

I am very very impressed with your blog, I hope you will have more blogs or more articles to bring to readers. You are doing a very good job.

P.D.U.S.U. B.A 3rd Year Exam Result
CCSU BA 3rd Year Result
BA Final Year Result MGSU Name Wise