Wednesday 15 September 2010

import - docker revert changes to container -



import - docker revert changes to container -

i'm trying snapshot docker container can revert single point in time.

i've looked @ docker save , docker export neither of these seems i'm looking for. missing something?

you might want utilize docker commit. command create new docker image 1 of docker containers. way can create new container later on based on new image.

be aware docker commit command won't save info stored in docker data volumes. need create backups.

for instance if working next dockerfile declares volume , write date every 5 seconds 2 files (one beingness in volume, other not):

from base of operations volume /data cmd while true; date >> /data/foo.txt; date >> /tmp/bar.txt; sleep 5; done

build image it:

$ docker build --force-rm -t so-26323286 .

and run new container it:

$ docker run -d so-26323286

wait bit running docker container have chance write date 2 files couple of times.

$ docker ps container id image command created status ports names 07b094be1bb2 so-26323286:latest "/bin/sh -c 'while t 5 seconds ago 5 seconds agitated_lovelace

then commit container new image so-26323286:snapshot1:

$ docker commit agitated_lovelace so-26323286:snapshot1

you can see have 2 images availables:

$ docker images | grep so-26323286 so-26323286 snapshot1 03180a816db8 19 seconds ago 175.3 mb so-26323286 latest 4ffd141d7d6f 9 minutes ago 175.3 mb

now let's verify new container run so-26323286:snapshot1 have /tmp/bar.txt file:

$ docker run --rm so-26323286:snapshot1 cat /tmp/bar.txt sun oct 12 09:00:21 utc 2014 sun oct 12 09:00:26 utc 2014 sun oct 12 09:00:31 utc 2014 sun oct 12 09:00:36 utc 2014 sun oct 12 09:00:41 utc 2014 sun oct 12 09:00:46 utc 2014 sun oct 12 09:00:51 utc 2014

and witness such container not have /data/foo.txt file (as /data info volume):

$ docker run --rm so-26323286:snapshot1 cat /data/foo.txt cat: /data/foo.txt: no such file or directory

finally if want access /data/foo.txt file in first (still running) container, can utilize docker run --volumes-from option:

$ docker run --rm --volumes-from agitated_lovelace base of operations cat /data/foo.txt sun oct 12 09:00:21 utc 2014 sun oct 12 09:00:26 utc 2014 sun oct 12 09:00:31 utc 2014 sun oct 12 09:00:36 utc 2014 sun oct 12 09:00:41 utc 2014 sun oct 12 09:00:46 utc 2014 sun oct 12 09:00:51 utc 2014 sun oct 12 09:00:56 utc 2014 sun oct 12 09:01:01 utc 2014 sun oct 12 09:01:06 utc 2014 sun oct 12 09:01:11 utc 2014 sun oct 12 09:01:16 utc 2014

import load save export docker

No comments:

Post a Comment