1.

Explain different types of volume mounts in docker.

Answer»

There are three mount types available in Docker   

  • Volume mounts are the best way to persist data in Docker. Data are stored in a part of the host filesystem which is managed by Docker containers. (/var/lib/docker/volumes/ on Linux).Main advantages of using volume mounts are
    • Easy to use and backup
    • Docker CLI commands or the Docker API can be used to manage volume mounts.
    • Linux and Windows containers support volume mounts.
    • Volumes could be shared securely among MULTIPLE containers.
    • New volumes can use pre-populated content by a container.

Starting with Docker 17.06, -v or --volume flag and --mount flag could be used for docker SWARM services and standalone containers. To create a docker volume. For EG:

docker volume create my-vol” creates new volume  “my-vol”.

We can inspect a volume with the command “docker volume inspect

For eg:

docker volume inspect my-vol “ gives the output

[ {     "DRIVER": "local",     "Labels": {},     "Mountpoint": "/var/lib/docker/volumes/my-vol/_data",     "Name": "my-vol",     "Options": {},     "Scope": "local" } ]

If we need to start a container with “my-vol”

  • With -v flag

docker run -d  --name devtest -v my-vol:/app nginx:latest”. Here nginx images with the latest tag are executed with using volume mount “my-vol”

  • With --mount flag

“docker run -d --name devtest --mount \ source=my-vol,target=/app nginx:latest”

  • Bind mounts may be stored anywhere on the host system. A file or directory on the host machine is mounted into a container unlike volume mounts where a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents. Non-Docker processes on the Docker host or a Docker container can modify them at any time.
  • tmpfs mounts are stored in the host system’s memory only and are never written to the host system’s file system. When the container stops, the tmpfs mount is removed, and files won’t persist.


Discussion

No Comment Found