Docker volume mounting for registry persistence¶
Docker volume mounting for registry persistence refers to the practice of mapping a host directory to the container's storage path to preserve Docker images across container lifecycles^[600-developer__docker__Dockerfile__Dockerfile-01.md]. Without this configuration, images stored in a Docker Registry will be lost if the container is removed.
Implementation¶
To enable persistence, the Docker Registry container must be started with the -v (volume) flag. This command maps a specific directory on the host machine to the /var/lib/registry directory inside the container^[600-developer__docker__Dockerfile__Dockerfile-01.md].
Command Syntax¶
The standard command to launch a persistent registry is as follows^[600-developer__docker__Dockerfile__Dockerfile-01.md]:
docker run -d -p 5000:5000 -v /host/path:/var/lib/registry --name registry registry:2
In this example:
* -d: Runs the container in detached mode (in the background).
* -p 5000:5000: Publishes the container's port 5000 to the host's port 5000.
* -v /host/path:/var/lib/registry: Mounts the host directory (e.g., C:/docker.resistry or a Unix path) to the container's data directory^[600-developer__docker__Dockerfile__Dockerfile-01.md].
* --name registry: Assigns a custom name to the container.
* registry:2: Specifies the official Registry version 2 image.
Related Concepts¶
- Docker Registry
- Dockerfile
- [[Data Persistence]]
Sources¶
^[600-developer__docker__Dockerfile__Dockerfile-01.md]