top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Docker: How a docker container communicate to another docker container in the same/different host ?

+1 vote
566 views

There are multiple cases:
1. A number of containers have been launched in the same host. how these container communicate to each other
2. Out of "x" numbers of containers in the same host, I want to enable communication between two specific containers. How I can achieve this ?
3. Containers have been launched into different hosts machine and I want to enable communication between these containers. What are the options available ?

posted Aug 31, 2017 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Let's say we have two containers on the same host, run these commands

Create a network:

docker network create -d bridge "your-created-network" // Your network, you can name anything
docker run -d -p 8080:80 --network="your-created-network" --name=nginxone nginx:alpine

and change the nginx port to 8081 to up another container of nginx

docker run -d -p 8081:80 --network="your-created-network" --name=nginxtwo nginx:alpine

to communicate between these two containers you need to execute:

docker exec -it nginxtwo sh
ping nginxone  // this will work

if you want to communicate between two specific containers, add your created network to those containers.
For the second case, I haven't tried but you can use boot2docker or apache.

answer Jan 23, 2018 by Shivam Kumar Pandey
Similar Questions
+1 vote

I know docker client is used to launch docker containers on docker host. Which protocol is used between docker client and docker host ? Is it necessary docker client run on the same host in which docker client run ?

+3 votes

I have one host machine and want to run multiple docker containers and each container I want to run different web servers.
How I can achieve this ? Sharing the steps would be good enough for me to proceed. Thanks in advance.

+1 vote

I have one application which is running in a stand alone system. I want to run the same application in a docker container. I also want to know that is only one process that can run in a docker container ?

...