Docker Volumes when updating the image -


i'm newbie docker , i'm trying better understand volumes topic. here see that:

  • volumes initialized when container created. if container’s base image contains data @ specified mount point, existing data copied new volume upon volume initialization. (note not apply when mounting host directory.)
  • data volumes can shared , reused among containers.
  • changes data volume made directly.
  • changes data volume not included when update image.
  • data volumes persist if container deleted.
  • data volumes designed persist data, independent of container’s life cycle. docker therefore never automatically deletes volumes when remove container, nor “garbage collect” volumes no longer referenced container.

which clear, except this:

  • changes data volume not included when update image.

and i'm struggling having better understanding of this. can provide me more clear overview, possibly basic example?

thanks!

volumes live outside of container's filesystem. mounted @ runtime data in them not live in container. let's take example:

j@host $ docker volume create --name my-data

this creates volume (no containers yet) called my-data. create new container , mount volume inside container @ /inside/data.

j@host $ docker run -it -v my-data:/inside/data --name container1 alpine:3.3 sh

now i'm in shell inside container, create new file inside folder /inside/data.

root@container1 $ cd /inside/data && touch my-file

now /inside/data isn't in container filesystem, it's volume lives outside of container, mounted in. if stop container, , _don't mount volume in, file isn't there.

root@container1 $ exit j@host $ docker run -it --name container2 alpine:3.3 sh root@container2 $ ls /inside/data ls: /inside/data: no such file or directory root@container2 $ exit 

in fact, folder isn't there! because didn't mount @ location. i'm using volumes, data is not persisted in container. how find again? is persisted in volume (my-data). let's take @ mounting container (i don't need mount @ same point, i'm going use different).

j@host $ docker run -it -v my-data:/different/folder --name container3 alpine:3.3 sh root@container3 $ ls /different/folder my-file root@container3 $ exit 

ok can data , mount around different containers. data in volume actually live? on host filesystem. can check doing:

j@host $ docker volume inspect my-data [     {         "name": "my-data",         "driver": "local",         "mountpoint": "/var/lib/docker/volumes/my-data/_data",         "labels": {},         "scope": "local"     } ] 

ok, tells me on host machine volume located, let's take @ what's in there (we need sudo because it's owned root).

j@host $ sudo ls /var/lib/docker/volumes/my-data/_data my-file 

and there's file!


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -