Configuring Docker for Private Registry Access
To access a private Docker registry, you need to configure Docker to recognize the registry and provide the necessary authentication credentials.
Configuring the Docker Daemon
The first step is to configure the Docker daemon to trust the private registry. You can do this by adding the private registry's URL to the insecure-registries
configuration in the Docker daemon configuration file.
## Edit the Docker daemon configuration file
sudo vi /etc/docker/daemon.json
## Add the private registry URL to the "insecure-registries" list
{
"insecure-registries": ["private-registry.example.com"]
}
## Restart the Docker daemon
sudo systemctl restart docker
Configuring the Docker CLI
Next, you need to configure the Docker CLI to authenticate with the private registry. You can do this by adding the registry's credentials to the Docker configuration file, typically located at ~/.docker/config.json
.
## Log in to the private registry
docker login private-registry.example.com
## The login command will create or update the ~/.docker/config.json file
cat ~/.docker/config.json
{
"auths": {
"private-registry.example.com": {
"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="
}
}
}
Alternatively, you can manually edit the ~/.docker/config.json
file and add the registry's credentials:
{
"auths": {
"private-registry.example.com": {
"username": "your-username",
"password": "your-password"
}
}
}
Pulling and Pushing Images
Once you have configured the Docker daemon and the Docker CLI, you can pull and push images to the private registry using the standard Docker commands:
## Pull an image from the private registry
docker pull private-registry.example.com/my-app:latest
## Push an image to the private registry
docker push private-registry.example.com/my-app:latest
By following these steps, you can successfully configure Docker to access and interact with a private Docker registry.