2

I have a Wordpress container which used to work before. Due to the changes on the linked container, the Wordpress container couldn't be started anymore now (the EntryPoint code has error)

Since the Wordpress container contains some configurations which are not stored in the host filesystem, I shouldn't redoing docker run for now. Instead, I wish to bash into the stopped container, check all changed files, and back up those files first.

Is there a way to execute bash on a stopped container? How to do so?

2 Answers 2

5

More natural way would be to use the docker diff to inspect changes to the container's filesystem. - will only show the names of the changed files.

If you are lucky to use a mature container and the changes were made on the volumes, you could start a new container with --volumes-from <stopped container>.

Alternatively you could start the stopped container and then do exec to get into it.

Third option would be to commit stopped container as an image and start a new one from it.

Sign up to request clarification or add additional context in comments.

6 Comments

I did docker diff but only see a few changes. By right, there must be quite a lot images in /wp-content/uploads folder. Does docker diff always shows all changed file in the container compared to the initial image?
I couldn't start then exec. start terminates the container prematurely (due to error in EntryPoint) before I have chance to exec
if you don't see the files with the docker diff then chances are they remained on the volumes. You may then easily recover them by doing docker run -it --volumes-from <stopped container> ubuntu .
ah, yes, it is there!! Thx alot! :). So now, could I safely do commit the stopped container and execute docker run -it --volumes-from <stopped container> <new image name>?
You have to commit the stopped container only if there are changes outside volumes that you would like to preserve for the future instances, and it is a bad practice - normally you would add such changes via Dockerfile. With this newly committed or the original image you can indeed do run with --volumes-from. You might also want to give a good read to the data volume containers concept.
|
0

docker run -v /mydata --name mydata ubuntu /bin/false

then ...

docker exec mydata touch /mydata/foo # doesn't work if not running :-(

A good solution is to run a throwaway container every time you want to attach to the data container. In this case the data container itself could be entirely empty, as the temporary container would have the OS tools.

$ docker run --rm --volumes-from mydata -it ubuntu bash
root@645045d3cc87:/# ls /mydata
root@645045d3cc87:/# touch /mydata/foo
root@645045d3cc87:/# exit
exit

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.