What is the meaning and usage of volume in Dockerfile?

1

In a Dockerfile file, what is the meaning of the statement:

VOLUME /arquivos

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

    
asked by anonymous 27.03.2018 / 04:01

2 answers

2

In dockerfile the volumes tell the docker the mount points in the containers created from the image you are building (with dockerfile).

This allows the docker to allocate volumes dynamically, or to inform the image consumers of the mount points required to maintain the state of the containers created with the image.

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

You can also report multiple volumes (do not have to be one) in multiple sentences or array format: as below.

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

In the Docker Run / Docker Create subcommands the short -v parameter 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 even ignore them. There is no validation whatsoever about this, so you have to be careful and careful.

    
27.03.2018 / 18:31
1

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

VOLUME / opt / host / opt / container

In the 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 docker run you can pass it or ask docker to do it automatically.

EXPOSE 8080

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

docker run -p 8080

Or we can use:

docker run -p 80: 8080

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

    
27.03.2018 / 16:19