trikoder_beta
trikoder_beta

Reputation: 2880

How to restore snapshot of docker image (for testing purpose, every test on this same docker image)

I want to create an environment to run test on already prepared image. However docker stores a results from previously run tests, what can be illustrated by:

sudo docker run -t myname/test_base echo "test" >> /tmp/t; cat /tmp/t

test

sudo docker run -t myname/test_base echo "test" >> /tmp/t; cat /tmp/t

test
test

what I should do, if I simply want to restore initial state of image?

sudo docker run -t myname/test_base echo "test" >> /tmp/t; cat /tmp/t

test

<some magic>

sudo docker run -t myname/test_base echo "test" >> /tmp/t; cat /tmp/t

test

Upvotes: 0

Views: 269

Answers (1)

seanmcl
seanmcl

Reputation: 9946

This is not the docker image you are changing. It's your host file system. The bash redirection you're using '>>' puts the stdout of the docker run command into /tmp/t on your host file system. To restore the state, you need to remove the file.

I think what you want is

docker run test_base bash -c 'echo test >> /tmp/t'

which will put the echo in the container file system, which will be lost when the process exits.

Upvotes: 1

Related Questions