saurg
saurg

Reputation: 347

Reusing a previoulsy used docker container

If I am in a docker container, then it can be stopped by using Ctrl+P+Q or by using exit command but after exiting from this container, how to save its state so that I can use same container with all the changes still there. Also if I use docker commit to save the container, then it just hangs. So is there any method to use a container from the same state at which I exited from it?

Upvotes: 2

Views: 3547

Answers (1)

piyushj
piyushj

Reputation: 1552

You could place the source control operations into the last RUN that is listed in the Dockerfile.

But in order to make this a unique command, thus ensuring it gets run each time, you could wrap the Docker build in another script that generates a uniquely-numbered mini-script for the clone operation.

This step would insert the invocation of that script into the Dockerfile that is generated on-the-fly just prior to build time, such that for the operation that must be run every time – the clone – its RUN statement is indeed unique, i.e.

RUN /bin/sh /foo-1234567abc.sh

where foo-1234567abc is uniquely generated for each build (and subsequent executions create something like foo-26190def.sh) and contains the clone operation, i.e.

cd /some/dir && /usr/bin/git clone http://some.git.server/your-repo.git

which itself may only very infrequently — or never — change.

This guarantees that Docker will run the clone during each build while having the advantages of being both fully automated and ensuring that the cache is used right up to that last unique RUN.

For more information see here

Upvotes: 1

Related Questions