Torbjorn Zetterlund

Wed 21 2022

Recover all files from an existing docker container

by bernt & torsten

I had a little mishap the other day, I had built an app and created a docker container which I later deployed to Google Cloud Run, before I had pushed a copy of the code to GitHub, my drive got a problem and I lost the code I had on my laptop.

After I got my hard drive fixed, I wanted to see if I could recover the code from the docker container that I had deployed in the cloud, I had a copy of my container in the Google Container Registry.

Container Registry

Maybe this will help others who faced the same issue I did, and how to retrieve the files from a container. First, you have to log in to your google project, that is straightforward, I used gcloud command from the command line like this.

gcloud auth login

The next step that I took was to extract the container from Google Container Registry, I did that by copying the container registry with the docker pull command.

docker pull

This pulled the container to my local laptop, next I need to extract the files I use docker cp here is the syntax:


You can read more about the docker command here –

To get the container ID I use the docker ps command to get the downloaded Container id, when I have the container ID, I use the docker cp command like this:

docker cp 49a19352f411:/app /Users/torbjornzetterlund/Sites/localhost/gpi-techlab

To get the files in the container download to a path that I specified.

That is it – worked for me – hope it works for you.