Skip to content
Advertisement

Can I run docker diff from a container on the same host as the container I want to run the diff on?

I have two containers running on a host. When I’m in container A I want to run a diff on container B compared to it’s image to see what has changed in the filesystem. I know this can be ran easily from the host itself, but I’m wondering is there any way of doing this from inside container A, to see the difference on container B?

Advertisement

Answer

You can run any docker commands from within container which will communicate with host docker daemon if:

  • You have access to docker socket inside container
  • You have docker client inside container

You can achieve first condition by mounting docker socket to container – add following to your docker run call: -v /var/run/docker.sock:/var/run/docker.sock.

The second condition depends on your docker image.

If you are running bare Ubuntu image you can have shell inside container which will be able to do what you want with following command:

docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu:latest sh -c "apt-get update ; apt-get install docker.io -y ; bash"

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement