Reputation: 717
I am trying to execute the same command in several docker containers at once.
Run the command only to one container instance work:
sudo docker exec -it 0c3108d66666 mkdir newfolder && sudo touch newfile.txt
I want run the command specifying more containers ids or all, something similar to:
sudo docker exec -it 0c3108d666666 cf65935c7777 mkdir newfolder && sudo touch newfile.txt
This generate an error exec failed, I have searched and tried but nothing.
Upvotes: 0
Views: 135
Reputation: 126193
Obvious solution is a shell loop. The tricky part is managing the exit code, which requires using a subshell:
(for container in 0c3108d666666 cf65935c7777; do
sudo docker exec -it $container mkdir newfolder || exit;
done) && sudo touch newfile.txt
You could also write a shell function to do this without a subshell, which may be more convenient for some uses.
Upvotes: 1
Reputation: 1323613
Not only the docker exec
command take only one container parameter, but I don't even see an issue requesting that specific feature in moby/moby
.
That means you would need to get the list of containers you want, loop over that list and call your docker exec
command (possibly in background, in order to launch them as parallel as possible)
Upvotes: 1