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.
Each of the scripts can be found here:
cp_docker
#
1
2
3
4
5
6
7
|
#!/bin/bash
IMAGE=$1
FROM_PATH=$2
TO_PATH=$3
docker cp $(docker create --rm $IMAGE):$FROM_PATH $TO_PATH
|
diff_docker_cmd
#
1
2
3
4
5
6
7
8
9
|
#!/bin/bash
IMAGE1=$1
IMAGE2=$2
CMD=$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 && rm /tmp/output*.tmp
|