Docker Copy From Exited Container

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)

1
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.

1
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.

1
docker run -i --entrypoint=sh user/copied_from_foo

From the interactive terminal, ll or 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.

1
2
cd ..
dir

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.

1
docker ps

Copy locally, I like to copy to a temp folder in my local machines root.

1
2
3
4
cd\
mkdir temp
cd temp
docker cp [NEW CONTAINER ID]:/some folder/ .

The content from the container’s some folder folder is now local in the root at /temp/.

References