Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Copy files to a stopped Docker container (and vice versa)

Copy files to a stopped Docker container (and vice versa)


Recently I had to copy a file to docker container to make some immediate changes on it. The container crashed and kept restarting every time we try to bring it up, so I was not able to access the container's file system. So while looking for a solution, I learned that it's possible to copy a file to a stopped container using the docker cp command.

You can also use the same command to copy a file from the docker container to your local environment.

This is how to copy a file into a docker container.

docker cp <local-filename> <container-name>:<file-location-to-copy>

Here's an example:

docker cp AppData integrationapi:/usr/local/src/integrationapi/AppData

That's it...I hope this will help someone :)

View and edit files inside a docker container.

How to view and edit files inside a docker container.


Today I deployed a new service in a docker container and found that service wasn't working as expected. Since it was working in my local environment, I guessed that it could be due to a small issue. So I decided to access the files inside the docker container and do some manual debugging. I wanted to write down the command to access the terminal of the container in my blog for my own reference. Hope this will help others too.

So here's how to get into the terminal / bash prompt of your container. Just run the following command.

docker exec -it <your-container-name> bash
That's it. I hope you know that you can get a list of all running instances by giving the docker ps command ;)

One last thing, since I mentioned about editing files. Docker by default, doesn't come with any editors like nano or vim. You may need to install them manually. It's super easy, in case you don't remember, just run:

apt update
apt install vim
Hope it helps :)