Saturday, November 23, 2024
HomeDevOpsHow to setup your own local private Docker registry

How to setup your own local private Docker registry

Docker at its core is a way to separate an application and the dependencies needed to run it from the operating system itself. To make this possible Docker uses containers and images. A Docker image is basically a template for a filesystem. When you run a Docker image, an instance of this filesystem is made live and runs on your system inside a Docker container. By default, this container can’t touch the original image itself or the filesystem of the host where Docker is running. It’s a self-contained environment.

Whatever changes you make in the container are preserved in that container itself and don’t affect the original image. If you decide you want to keep those changes, then you can “commit” a container to a Docker image (via the docker commit command). This means you can then spawn new containers that start with the contents of your old container, without affecting the original container (or image). If you’re familiar with git, then the workflow should seem quite similar: you can create new branches (images in Docker parlance) from any container. Running an image is a bit like doing a git checkout.

To continue the analogy, running a private Docker registry is like running a private Git repository for your Docker images.

In this will show how to run a Docker registry locally on a local network. We assume that the host which will run Docker registry has the Docker already installed and can be accessed either via hostname or IP address. Alternatively, you can run your local Docker registry on a local system using 127.0.0.1 or localhost In our scenario we will run docker on host: foxutech.local. Let’s start by running a Docker registry container on foxutech.local host:

# docker run -d -p 5000:5000 registry
0774f3340b58f31c5f13aaa16f12f262270b6cc4d262811e2e826e91cce1764d

Next from a client host, use docker command to obtain an IMAGE-ID of the docker image you wish to push to your local repository:

# docker images

Take a note of the IMAGE ID eg. 4640c27a97a5. Now that we have an IMAGE ID of the docker image we would like to upload to our own local docker registry we can use docker tag command to tag this image for an upload:

# docker tag 4640c27a97a5 foxutech.local:5000/etcd

Once we have tagged our image we can use docker push command to upload it our local docker registry:

# docker push foxutech.local:5000/etcd
The push refers to a repository [foxutech.local:5000/etcd]
5f70bf18a086: Pushed
bf789d742ec0: Pushed
56e9038de247: Pushed
latest: digest: sha256:6cc3e24333188b336552fb538acd60bc6d4e5672cb8fa351cd90b675b4c2afdc size: 1563

Lastly, search your local Docker registry to confirm a correct upload:

# docker search foxutech.local:5000/etcd
NAME             DESCRIPTION   STARS     OFFICIAL   AUTOMATED
library/etcd
# docker pull foxutech.local:5000/etcd

Use Registry with S3 bucket to store Images

Here is a slightly more complex example that launches a registry on port 5000, using an Amazon S3 bucket to store images with a custom path, and enables the search endpoint:

# docker run -e SETTINGS_FLAVOR=s3 -e AWS_BUCKET=mybucket -e STORAGE_PATH=/registry -e AWS_KEY=myawskey -e AWS_SECRET=myawssecret -e SEARCH_BACKEND=sqlalchemy -p 5000:5000 registry

For complete configuration refer docker/docker-registry

Install your Registry (on your server or locally)

Docker-Registry is a simple Python app, installing it is straight-forward:

# git clone https://github.com/dotcloud/docker-registry.git
# cd docker-registry
# cp config_sample.yml config.yml
# pip install -r requirements.txt
# gunicorn --access-logfile - --log-level debug --debug -b 0.0.0.0:5000 -w 1 wsgi:application

Your Registry is now running on localhost (port 5000) in a development flavor and using local storage. Obviously, in a production environment, you might want to run the Registry on port 443 (or 80 on a local network) and make it accessible on a hostname like “registry.domain.tld”, and point it to use S3 or other storage.

RELATED ARTICLES
- Advertisment -

Most Popular

Recent Comments