简体   繁体   English

我可以在与要运行diff的容器相同的主机上运行docker diff吗?

[英]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 AI want to run a diff on container B compared to it's image to see what has changed in the filesystem. 当我进入容器AI时,要对容器B进行比较(与它的映像相比),以查看文件系统中发生了什么变化。 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? 我知道可以很容易地从主机本身运行它,但是我想知道是否有任何方法可以从容器A内部执行此操作,以查看容器B上的区别?

You can run any docker commands from within container which will communicate with host docker daemon if: 您可以在容器内运行将与主机docker守护程序通信的容器中的任何docker命令,如果:

  • You have access to docker socket inside container 您可以访问容器内的Docker套接字
  • You have docker client inside container 您在容器内有Docker客户端

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 . 您可以通过将docker套接字安装到容器来实现第一个条件-在docker run调用中添加以下内容: -v /var/run/docker.sock:/var/run/docker.sock

The second condition depends on your docker image. 第二个条件取决于您的docker映像。

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: 如果您运行的是裸露的Ubuntu映像,则可以在容器中包含外壳程序,该外壳程序将可以通过以下命令执行所需的操作:

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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在Docker容器环境中运行主机命令吗? - Can I run host commands with docker container environment? 我可以在 Linux Docker 容器中运行 JetBrains dotCover 吗? - Can I run JetBrains dotCover in a Linux Docker container? 我可以在仅64位主机内核上的64位docker容器中运行32位二进制文​​件吗? - Can I run a 32bit binary in a 64bit docker container on a 64bit only host kernel? docker 运行后将文件夹从容器复制到主机 - Copy folder from container to host after docker run 我已经在centos 7中安装了docker容器,但是docker容器和主机不在同一网络上,这就是为什么docker无法从外部访问的原因? - i have installed docker container in centos 7 but docker container and host are not on same network thats why docker is not accessible from outside? 如何在 linux 主机上运行 windows docker 容器? - How to run a windows docker container on linux host? 如果我在 docker 容器中运行 sudo dd if=/dev/zero of=/dev/sda 我的主机系统会中断吗? - if i run sudo dd if=/dev/zero of=/dev/sda in a docker container will my host system break? 无法从同一局域网中的另一台主机ping Docker容器 - Can not ping docker container from another host which is in the same LAN 如何使用非默认运行参数在AWS Elastic Beanstalk中运行Docker容器? - How can I run a Docker container in AWS Elastic Beanstalk with non-default run parameters? 在带有线保护的 docker 容器中时,为什么我只能从 docker 主机访问 nginx 而不能远程访问? - When in a docker container with wireguard, why can I only access nginx from the docker host and not remotely?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM