brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker cp works on stopped containers too

Docker
~/tips/tip-docker-cp-stopped

docker cp mycontainer:/etc/app/config.yml ./config.yml

Copies files out of or into a container, even a stopped one, without starting it.

A container crashed on start and the config it wrote is the thing you need to read. You cannot exec into it, but you can still get the file out.

docker cp copies files between a container and the host, and the container can be stopped.

docker cp mycontainer:/etc/app/config.yml ./config.yml
docker cp ./config.yml mycontainer:/etc/app/config.yml

The first line copies out, the second copies in. Directories work as well. The trailing part matters: docker cp mycontainer:/data/. ./data copies the contents of the directory, while leaving off the /. copies the directory itself into the destination.

It is also the quickest way to inspect a default config file from an image you have never used. Create the container without starting it, copy the file out, read it, and remove the container again. No running service required. I find that nicer than hunting through documentation for the default path.

The caveat: docker cp does not create missing parent directories on the destination, and a file copied into a running container is gone when the container is recreated. For anything that must survive, use a volume.

Further reading: docker container cp, On this site: docker update –restart changes the policy without recreating the container, On this site: docker diff shows what a container changed in its filesystem, On this site: 🐳Comprehensive Guide: Updating Docker Containers via the Unraid Terminal

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link