所有正在运行的容器上的Docker exec [英] Docker exec on all running containers

查看:114
本文介绍了所有正在运行的容器上的Docker exec的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在服务器上运行多个docker容器,并且需要对所有容器上的存储库执行git pull。

I am running several docker containers running on my server, and need to exec a git pull for a repository that is on all of them.

我尝试使用

docker exec $(docker ps -q) bash -c "cd /var/www/html && git pull"

但是它的错误如下:

OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"606a1083d0be\": executable file not found in $PATH": unknown

它曾经工作过一点,但是突然由于没有明显的原因而停止工作(我没有t更改任何docker配置)

It worked at one point, but then suddenly stopped working for no apparent reason (I didn't change any docker configuration)

注意: docker ps -q 的输出仅是容器ID:

Note: the output of docker ps -q is only container ids:

511c76a25dcc
995bd453c467


推荐答案

使用Docker exec可以一次在一个容器上运行该命令,但是从您的问题中可以想要在所有正在运行的容器上运行命令,就可以了。

Using Docker exec you can run the command on the container one at a time, but from your Question you want to run the command on all running container, here you go.

    for containerId in $(docker ps -q)
    do
        docker exec -it $containerId bash -c 'cd /var/www/html && git pull'
    done

我认为git已安装在所有运行容器和所有库中在bash上

I assume git is already installed in all running container and all base on bash

或更紧凑的形式可以是

for i in `docker ps -q`; do docker exec -it $i bash -c 'cd /var/www/html && git pull'; done

这篇关于所有正在运行的容器上的Docker exec的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆