I needed to copy data from an exited container to debug a database deployment failure. The container was in an error state so I could not start it again.
We need to look for the container ID with the list containers function (this is the
ps processes command and the
-a means show all. The default only shows those running)
docker ps -a
Commit the containers file changes or settings into a new image, most of the examples I could find put in
user/something which helps to identify the image.
docker commit [EXITED CONTAINER ID] user/copied_from_foo
Now run the image in interactive mode (this is the
-i option) so the container stays up. If you dont want a random name then include
--name sweet-container-name. I like the random names as I know those were just for a hoon and can be trashed.
docker run -i --entrypoint=sh user/copied_from_foo
From the interactive terminal,
dir to find what you want and to figure out the folder stucture. I normally try get to the root and filter out from there.
Hop over to another PWSH window on your local machine.
Find the new container id that is running in iteractive mode, here the random name and status are helpful, it will be only a few seconds old.
Copy locally, I like to copy to a temp folder in my local machines root.
The content from the container’s
some folder folder is now local in the root at