Most Docker images normally come from the official Docker index, but in some environments that is either too slow or not appropriate for private images that include internal code. In that case, setting up your own Docker image registry becomes a practical option.
Docker provided a tool called Docker Registry for self-hosting an image index on a local network, which works well for sharing images inside a company.
This post records one installation process as a reference.
Environment
I used CentOS 6.5 x64. Docker Registry was written in Python, so the environment requirements were not especially strict.
Installation
Install dependencies
1 | yum install python-devel libevent-devel python-setuptools gcc xz-devel |
Add a docker user and storage directory
For safety, create a dedicated docker user and a storage directory for registry data:
1 | useradd docker |
Install with easy_install
Since Docker Registry is a Python application, it can be installed directly with easy_install (or pip):
1 | easy_install docker-registry |
Configure Docker Registry
After installation with easy_install, the package may end up in a path like:
1 | /usr/lib/python2.6/site-packages/docker_registry-0.7.3-py2.6.egg |
Go into its config directory and copy the sample config:
1 | cd /usr/lib/python2.6/site-packages/docker_registry-0.7.3-py2.6.egg/config |
Then update at least these two settings in config.yml:
1 | sqlalchemy_index_database: _env:SQLALCHEMY_INDEX_DATABASE:sqlite://///opt/docker_data/registry/docker-registry.db |
Configure Nginx
For convenience, you can register a domain such as docker.knktc.com in your local DNS and proxy it through Nginx.
Example configuration:
1 | upstream docker-registry { |
Test startup
After starting Nginx, test the registry as the docker user:
1 | /usr/bin/gunicorn --debug -k gevent -b 0.0.0.0:5000 -w 8 docker_registry.wsgi:application |
You may hit several import errors at first. If so, just install the missing Python modules one by one.
If browsing to http://docker.knktc.com returns:
1 | "docker-registry server (dev) (v0.7.3)" |
then the registry is running successfully.
Manage it with supervisord
Both official and community guides recommended using supervisord to keep Docker Registry running.
Example program section:
1 | [program:docker-registry] |
Usage test
After the registry is ready, you can tag a local image to push it there:
1 | docker tag localimage docker.knktc.com/knktc/testimage |