In Dockerfiles and docker-compose files I often stumble across two notations.
Example docker-compose:
volumes:
- ./app/:/usr/src/app/
Example Dockerfile
COPY ./Pipfile /usr/src/app/Pipfile
The second one means, take the file/folder from my machines directory ./Pipfile and Copy it to the image in the directory /usr/...? But what does the first one mean?
Thanks.
In the case of a bind mount
-v
or--volume
: Consists of three fields, separated by colon characters (:
).
The fields must be in the correct order, and the meaning of each field is not immediately obvious.
- In the case of bind mounts, the first field is the path to the file or directory on the host machine.
- The second field is the path where the file or directory is mounted in the container.
- The third field is optional, and is a comma-separated list of options, such as ro, consistent, delegated, cached, z, and Z. These options are discussed below.
In case of named volume: the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.
Here: the first argument is a path, /app/: so bind mount it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With