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.
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 eu.gcr.io/techlab-coding-team/[email protected]:bb0eb8ca32ff910cbbd1eb01ec2f5c11c59c476e5bd5278e1ca6f54d79a444d8
This pulled the container to my local laptop, next I need to extract the files I use
docker cp here is the syntax:
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|
You can read more about the docker command here – https://docs.docker.com/engine/reference/commandline/cp/
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.
Leave a Reply