Docker container linking for registry¶
Docker container linking allows multiple Docker containers to communicate with each other directly. In the context of a Docker [[registry|Docker Registry]], this feature is commonly used to connect a web-based user interface (UI) to the registry service, enabling visual management of container images.
Configuration¶
To set up a linked registry environment, two containers are typically required: the registry service itself and a web frontend container^[600-developer__docker__Dockerfile__Dockerfile-01.md].
Registry Service¶
First, the registry service container is started. The following command runs the registry:2 image, maps port 5000, and names the container registry-srv^[600-developer__docker__Dockerfile__Dockerfile-01.md]:
docker run -d -p 5000:5000 --name registry-srv registry:2
Linked Web UI¶
Next, the web UI container is launched with the --link flag. This flag connects the web container to the registry-srv container^[600-developer__docker__Dockerfile__Dockerfile__Dockerfile-01.md].
- Container Linking: The
--link registry-srvargument enables the web container to discover and connect to the registry service. - Environment Variables: Environment variables are passed to the web container to configure the connection details, specifically pointing to the internal registry URL^[600-developer__docker__Dockerfile__Dockerfile-01.md].
Example command:
docker run -it -p 8080:8080 --name registry-web --link registry-srv -e REGISTRY_URL=http://registry-srv:5000/v2 -e REGISTRY_NAME=localhost:5000 hyper/docker-registry-web
In this configuration, the registry URL (http://registry-srv:5000/v2) uses the alias registry-srv, which resolves to the linked container's internal IP address^[600-developer__docker__Dockerfile__Dockerfile-01.md].
Related Concepts¶
- Dockerfile
- [[Container Networking]]