What is the meaning and form of volume use in Dockerfile?

Asked

Viewed 6,011 times

4

In a Dockerfile file what is the meaning of the instruction:

VOLUME /arquivos

I imagine it creates a volume, but how it’s used and what its real meaning is?

2 answers

5


On the dockerfile the volumes tell Ocker the mounting points in the containers created from the image you are building (with dockerfile).

This allows Docker to dynamically allocate volumes, or to inform consumers of the image which mounting points are required to maintain the state of the containers created with that image.

In Dockerfile the volumes are defined as: VOLUME /path/dir/1/ VOLUME /path/dir/2/

You can also enter multiple volumes (not one) in multiple sentences or in array format: as below.

VOLUME ["/path/dir/1/", "/path/dir/2/"]

In the subcommands Docker Run/Docker Create the short parameter -v or the long version --volume are used to map volumes. However, there is no obligation/restriction whatsoever. You can map the volumes that were determined in dockerfile or other volumes, or ignore them. There is no validation on that, so you need to be careful and careful.

0

Volume is when you need to share directory or folder between the host filesystem and the container filesystem.

VOLUME /opt/host /opt/container

In dockerfile always the first parameter refers to the host and the second parameter refers to the mapped to the container.

On the other hand, if you omit the second parameter as below, then in the Docker run you can pass it or ask the Docker to do it automatically.

EXPOSE 8080

When you run the "Docker run" command and pass the below command then a random port will be mapped in the host to the container port 8080.

Docker run -p 8080

Or we can use:

Docker run -p 80:8080

The above command means that the host port 80 will access the container port 8080.

  • Volume (no dockerfile) has no 2 parts and has no relation between host and container.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.