Creating Volume Mount from Dockerfile
Tested Infrastructure
Platform | Number of Instance | Reading Time |
---|---|---|
Play with Docker | 1 | 5 min |
Pre-requisite
Volumes are special directories in a container
Volumes can be declared in two different ways.
- Within a
Dockerfile
, with aVOLUME
instruction.
VOLUME /uploads
- On the command-line, with the
-v
flag fordocker run
.
$ docker run -d -v /uploads myapp
In both cases, /uploads
(inside the container) will be a volume.
Create a file with name volume and paste the following content to it:
FROM ubuntu:latest
RUN mkdir /data
WORKDIR /data
RUN echo "Hello from Volume" > test
VOLUME /data
Execute the following commands:
docker build -f volume -t collabnix/volume:1 .
docker run collabnix/volume:1
docker volume ls
cd /var/lib/docker/volumes
ls -ltr
cd ./<FOLDER_NAME_WITH_RANDOM_NUMBERS_&_CHARACTERS>
cd ./_data
cat test