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?

Pahlevi Fikri Auliya
  • 4,157
  • 8
  • 35
  • 71

2 Answers2

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.

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • 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? – Pahlevi Fikri Auliya Feb 07 '15 at 11:18
  • I couldn't `start` then `exec`. `start` terminates the container prematurely (due to error in EntryPoint) before I have chance to `exec` – Pahlevi Fikri Auliya Feb 07 '15 at 11:20
  • 1
    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 ubuntu` . – Mykola Gurov Feb 07 '15 at 11:24
  • ah, yes, it is there!! Thx alot! :). So now, could I safely do commit the stopped container and execute `docker run -it --volumes-from `? – Pahlevi Fikri Auliya Feb 07 '15 at 11:30
  • 1
    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](http://docs.docker.com/userguide/dockervolumes/#creating-and-mounting-a-data-volume-container) concept. – Mykola Gurov Feb 07 '15 at 11:51
  • You might find more comprehensive answers here: http://stackoverflow.com/questions/26153686/how-to-run-a-command-on-an-already-existing-docker-container – Dr. Jan-Philip Gehrcke Jun 10 '15 at 19:53
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
David Dehghan
  • 22,159
  • 10
  • 107
  • 95