Currently Browsing: Misc Tech

Docker copy files from image to local

You can’t easily copy file directly from a Docker image, but you can from a temporary container. Couple different ways to do it include:

Run a temp container and copy into local mounted directory, here it’s a directory named “tmp” inside your current directory:

docker run --rm -v $(pwd)/tmp:/tmp <image-name:tag> sh -c "cp -r /path/to/files/* /tmp"

You could do additional pre/post processing and gather additional files as needed, etc. by updating the sh (or bash or other) command.

Or you can simply copy a directory from a static temporary container to a tar file:

id=$(docker create <image-name:tag>)
docker cp $id:path - > local.tar
docker rm -v $id

Docker stats with container names

docker stats `docker ps | awk '{print $NF}' | grep -v NAMES`

Docker remove orphaned volumes

docker volume rm $(docker volume ls -qf dangling=true)

JSON parsing from the command-line

You don’t need to use Python for basic JSON parsing, just use `jq`:

jq – Command-line JSON processor


  • etc.

    SSH bypass host checking for dev Docker environment

    If you have a controlled environment where you are recreating SSH target instances, such as Docker containers, and have integration scripts (e.g., Jenkins), you will often run into SSH warnings that will prevent the CI/CD jobs from completing.

    If you are sure the target is in a controlled environment – e.g., within a Docker host/network, you can bypass the checks via:

    ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

    You could also update the UserKnownHostsFile but it can be tricky. There probably is a better setup than relying on SSH, but as we transition legacy workflow this works for now.

    « Previous Entries Next Entries »