简体   繁体   中英

Docker - running commands from all containers

I'm using docker compose to create basic environment for my websites (at the moment only locally so I don't care about security issues). At the moment I'm using 3 different containers"

  • for nginx
  • for php
  • for mysql

I can obviously log in to any container to run commands. For example I can ssh to php container to verify PHP version or run PHP script but the question is - is it possible to have such configuration that I could run commands from all containers running for example one SSH container?

For example I would like to run commands like this:

php -v
nginx restart
mysql 

after logging to one common SSH for all services.

Is it possible at all? I know there is exec command so I could add before each command name of container but it won't be flexible enough to use and in case of more containers it would be more and more difficult.

So the question is - is it possible at all and if yes, how could it be achieved?

Your question was:

Is it possible at all?

and the answer is:

No

This is due to the two restrictions you are giving in combination. Your first restrictions is:

  1. Use SSH not Exec

It is definitly possible to have an SSH daemon running in each container and setup the security so that you can run ssh commands in eg a passwordless mode

see eg Passwordless SSH login

Your second restriction is:

  1. one common SSH for all services

and this would now be the tricky part. You'd have to:

  • create one common ssh server in eg one special container for this purpose or using one of the containers
  • create communication to or between containers
  • make sure that the ssh server knows which command is for which container

All in all this would be so complicated in comparison to a simple bash or python script that can do the same with exec commands that in all the "no" is IMHO a better answer than trying to solve the academic problem of "might there be some tricky/fancy solution of doing this".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM