Skip to content

Latest commit

 

History

History
77 lines (48 loc) · 1.37 KB

create-a-volume-mount-from-dockerfile.md

File metadata and controls

77 lines (48 loc) · 1.37 KB

Creating Volume Mount from Dockerfile

Tested Infrastructure

Platform Number of Instance Reading Time
Play with Docker 1 5 min

Pre-requisite

  • Create an account with DockerHub
  • Open PWD Platform on your browser
  • Click on "Add New Node"

Volumes are special directories in a container

Volumes can be declared in two different ways.

  • Within a Dockerfile, with a VOLUME instruction.
VOLUME /uploads
  • On the command-line, with the -v flag for docker 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