Dockerfile Volume
In this lesson, we will use the VOLUME instruction to automatically create a mount point in a Docker image. When a container is created using this image, a volume will be created and mounted to the specified directory.
Step 1: Set up your environment:
mkdir volumescd volumesStep 2: Create the Dockerfile:
vi DockerfileStep 3: Build an Nginx image that uses a volume:
FROM nginx:latest
VOLUME ["/usr/share/nginx/html/"]Step 4: Build the new image:
docker image build -t nishanthkp/nginx:v1 .Step 5: Create a new container using the nishanthkp/nginx:v1 image:
docker container run -d --name nginx-volume nishanthkp/nginx:v1Step 6: Inspect nginx-volume:
docker container inspect nginx-volumeStep 7: List the volumes:
docker volume ls | grep [VOLUME_NAME]Step 8: Inspect the volumes:
docker volume inspect [VOLUME_NAME]Last updated