I want to communicate two containers in docker, I'm using netcat for the test. First I have created the Dockefile:
FROM ubuntu
WORKDIR /root
RUN apt-get update && apt-get install netcat iputils-ping -y
And added the image with:
docker build . -t ubuntu_netcat
Also I have created a new network:
docker network create --driver bridge nettest
Then I run two containers:
docker run --net=nettest --expose=8080 -it --name pc1 ubuntu_netcat
docker run --net=nettest --link=pc1 -it --name pc2 ubuntu_netcat
At first container (pc1) I listen on port 8080 with netcat command:
nc -vlk 8080
And I expect to communicate with it from the second container (pc2) executing:
nc -v pc1 8080
But I just got a connection refused:
root@c592b2015439:~# nc -v pc1 8080
pc1.nettest [172.18.0.2] 8080 (?) : Connection refused
I have been looking at the docker docs but all seems to be correct. In fact I can perform a ping between containers sucessfully, so they can reach one other, but I have something wrong with ports. ¿What am I doing wrong?
Thanks
docker network
question to link two Docker containers. Did you follow some blog to come up with this example, or come up with your own here? – Gelb