docker run -d -p 5000:5000 --restart=always --name registry registry:2
Make the registry can be accessed by others
Be default if you don’t do the following step, you can only access the registry from “localhost:5000”.
There are several ways to do this in the offical document, here is the simplest. You need to do the
following steps in every client machine who wants to connect to this registry server.
# 1. Edit the client side "/etc/default/docker" file, and add the following# content. Note that"lglbq177.lss.eemmcc.com" is your registry server domain name:DOCKER_OPTS="$DOCKER_OPTS --insecure-registry lglbq177.lss.eemmcc.com:5000"# 2. Restart your Docker service.sudo service docker stop
sudo service docker start
# 0. You need to have a local build image.# 1. Tag a local image and put it to the registry server.docker tag niqi/hds lglbq177.lss.eemmcc.com:5000/niqi/hds
# 2. Push the local image to the registry.docker push lglbq177.lss.eemmcc.com:5000/niqi/hds
# 3. Pull the image back from the registry.docker pull lglbq177.lss.eemmcc.com:5000/niqi/hds
Set the storage backend
By default, your registry stores its data on the local filesystem, inside the container.
You can set a directory to storge the registry data by running the following command to start the registry:
Run “docker-compose up -d” to start the registry server.
How to develop with Docker and the registry
First you need to know how to push and pull images to/from the registry.
# 1. Build the local Docker file.docker build -t niqi/hds .
# 2. Tag the created image with registry information.docker tag niqi/hds lglbq177.lss.eemmcc.com:5000/niqi/hds
# 3. Push the image to the registry.docker push lglbq177.lss.eemmcc.com:5000/niqi/hds
# After that, the image is in the registry and can be used by others.# In another Docker client, in order to use the registry, you must# modify your "/etc/default/docker" file by adding the line(without "#"):# DOCKER_OPTS="$DOCKER_OPTS --insecure-registry lglbq177.lss.eemmcc.com:5000"# Then you can pull the image from the registry:docker pull lglbq177.lss.eemmcc.com:5000/niqi/hds
Then you can create a Docker Compose file to leverage the registry:
After that you can start the compose file very easily:
# Note the "--allow-insecure-ssl" argument without with docker-compose# reports "HTTPS endpoint unresponsive and insecure mode isn't enabled"# error when pulling the images from the registry.docker-compose up --allow-insecure-ssl