Alexander Solonik
Alexander Solonik

Reputation: 10240

understanding parameters passed to -v in Docker

If i run the below command in my terminal,

$ docker create -v /dbdata --name dbdata training/postgres /bin/true

I kind of understand how the -v command works now, but i am still not quite understanding the above command quite well, i am essentially having a difficulty understanding how,

-v /dbdata 

works , what is that part of the command really doing ? I really fail to understand what -v /dbdata is really doing ?

Upvotes: 0

Views: 54

Answers (1)

larsks
larsks

Reputation: 312038

The -v /dbdata allocates a Docker volume and makes it available at /dbdata inside the container. A Docker "volume" is a chunk of storage allocated by the docker storage engine that is distinct from the rest of your container filesystem.

Quoting from the documentation:

Data volumes

A data volume is a specially-designated directory within one or more containers that bypasses the Union File System. Data volumes provide several useful features for persistent or shared data:

Volumes are initialized when a container is created. If the container’s base image contains data at the specified mount point, that existing data is copied into the new volume upon volume initialization.

  • Data volumes can be shared and reused among containers.
  • Changes to a data volume are made directly.
  • Changes to a data volume will not be included when you update an image.
  • Data volumes persist even if the container itself is deleted.

Data volumes are designed to persist data, independent of the container’s life cycle. Docker therefore never automatically delete volumes when you remove a container, nor will it “garbage collect” volumes that are no longer referenced by a container.

Upvotes: 2

Related Questions