Steps to configure private registry for Docker Windows server 2016
In this blog, we will show you the Steps to Configure private registry for docker Windows server 2016.
- Windows VM with docker service
- Linux VM (ubuntu or centos) with docker service
- Docker registry is a core open-source project and it’s available for free in docker hub.
- Docker registry will be installed locally so it will be secure and really very fast.
- Currently, docker has not provided any registry container to run on windows platform.
- So we need to use the Linux environment to configure the private registry to store our windows container images.
INSTALLING DOCKER ON WINDOWS
- We have already installed docker service on windows server 2016.
- Please check the URL to install the docker on windows 2016.
PREPARING THE UBUNTU ENVIRONMENT
Note: We are using the ubuntu flavour OS for this demo
- Login into ubuntu vm through putty.
- We have already enabled the root user to access the VM.
- Open the hostname file to add a hostname for this VM.
- Add a hostname for this VM along with IP. Save the changes and close the file.
- Update the available packages in the Ubuntu VM using apt-get update command.
INSTALLING THE DOCKER ON UBUNTU
- Use the below command to install the docker on ubuntu
apt-get install –y docker.io
- It will take few minutes to complete the operation.
- Check the docker service status using the below command.
service docker status
- To verify the docker version, type docker version command.
CREATING DOCKER REGISTRY
- You can find the docker official registry from the below URL.
- Use the docker pull command to pull the registry image from the docker hub.
docker pull registry
- You can verify the list of docker images using the below command.
- By default, docker registry will listen in port 5000. Launch the registry container using the docker run in detach mode along with port 5000 mapping.
docker run –name regdock -p 5000:5000 -d registry
- To verify the running container, execute the docker ps command.
- Now the container is listening in the port 5000. We can use the system name or IP to access this container from other machines.
VERIFY THE DOCKER REGISTRY CONTAINER
- To get into the registry container, run the below command.
docker exec -it regdock sh
- The default location of registry config file inside the container is
- Open the config.yml file in VI editor. By default, it listens to port 5000 and our private images will be stored under /var/lib/registry directory.
- By default, registry container listens through https. To disable the HTTPS, Go-to /etc/docker/ directory on your Ubuntu machine.
- Create a new file name named daemon.json file and add the below entry.
Note: Here privaterepo is the machine host name. Modify it based on your machine name.
- Save and close the file.
PREPARE THE WINDOWS DOCKER MACHINE
- Login into windows VM and Go-to C:\programdata\docker\config folder.
- Create a new filename daemon.json in that folder.
- Open the daemon.json file and add the below entry.
- Save and close the file.
- Go-to C:\Windows\System32\drivers\etc folder.
- Open the hosts file in the notepad.
- Add your ubuntu machine name and its IP address.
- Save and close the hosts file. Verify the hostname through PING command.
PREPARING THE IMAGES
- From the windows machine, type docker images to list the available images in the windows docker.
- The image name should be in the below format
private repo namespace:<portnumber>/imagename
- Rename the image name as shown as above. We are using nanoserver for this demo.
docker tag microsoft/nanoserver privaterepo:5000/mynanoserver
- Untag the old image name using the below command.
docker rmi microsoft/nanoserver:latest
- Use the below command to push docker images to docker registry.
docker push privaterepo:5000/mynanoserver
- We can use the below URL to view the list of images available in the private registry through a web browser.
Note: Privaterepo is the ubuntu machine name.
- Login into registry container and go-to /var/lib/registry/docker/registry/v2/repositories directory and you will able to view the pushed images.
Thanks for reading this blog. We hope it was useful for you to learn about configuring the private repository for docker windows 2016.