Cp

19 Aug 2021

Useful Docker Patterns (On GNU/Linux)

To easily copy files from a Docker image when you dont want to start a container, you can do the following:

1
docker cp $(docker create --rm $IMAGE):$FROM_PATH $TO_PATH

Sometimes it is useful to compare the output of a command between two Docker images, especially comparing different versions of a particular image:

1
2
3
docker run --rm -ti --entrypoint=bash $IMAGE1 -c "$CMD" > /tmp/output1.tmp
docker run --rm -ti --entrypoint=bash $IMAGE2 -c "$CMD" > /tmp/output2.tmp
diff -s /tmp/output1.tmp /tmp/output2.tmp

I have both these command patterns saved as executable Bash shell scripts on my system path as cp_docker and diff_docker_cmd respectively.