Docker Community Forums

Share and learn in the Docker community.

Communicate Between Containers

Please help if you know. I am new to Docker

I am working on a project that uses 2 different types of Containers.

1. Apache Server Docker (From ubuntu)
Contains to be called shell scripts and python scripts
2. System Usage Docker (From ubuntu)
User enter interactive mode from here.

I am connecting both container’s network to host “–net host”, now I want to communicate between these 2 containers. Calling a script to start up from docker 2 (System usage Docker) inside docker 1, is it possible to do it directly without using share volume or ssh method?

For example, inside Docker 2 -it mode, I will do something like " from docker 1 execute ./docker_1.sh" then this script will be running in Docker 1

Thanks for whoever willing to help.

Both docker 1 & 2 will be running at background, Docker 1 is using -d mode.

No, is not possible.

Communication between containers is managed at operating system level and it depends on two factors: By default Docker daemon attaches all containers to docker0 bridge, providing network address translation for their communication. So it is mandatory that network topology can identify containers’ network.

Then how about from docker container to host?
In the container, calling a script in host.

Thanks for you reply, I understand Network will be the option, so giving each container an address and the communication protocol between them will be by ssh? And then how about from docker container to host?
In the container, calling a script in host.

Hi @yf144114, Containers are isolated from the host so it wouldn’t be able to run any scripts on the host. You would need to treat the host like a remote server and run an sshd daemon on the host so that the container can ssh to the host just like it can ssh to any other container or remote server. Of course you can use rexec or any other remote execution mechanism.

To answer your original question if this is achievable without ssh the answer is yes, but you would need to run some sort of server that can be communicated with via an API. One solution might be to run a Python Flask service on docker 2 with a REST API that will run the script when the API is called from the docker 1 container.

1 Like