Docker Network Part 1
Docker Network example:
To show the flow between container, we will start a server. Server will accept a data from one client and pass it to another.
Exposing ports manually:
1. Start server:
$docker run --rm -ti -p 45678:45678 -p 45679:45679 --name echo-server ubuntu:14.04 bash
2. We use netact (nc) program to move bits from the server to the client. The data will passed throught our system on port 45678 and spit out on port 45679:
root@31f8cd3be562:/# nc -lp 45678 | nc -lp 45679
3. On another terminal, connect client 1 to the container . On a third terminal, connect client 2 to the container.
4. Then let's send the message "Let's send some data". The data passed from client 1 to the container then to client 2.
In case, you do not have nc on your computer you can use docker ubuntu and connect to the local host refering to it by host.docker.internal. This step is to be done for both client 1 & 2.
Exposing ports dynamically :
We use the same command as before without adding the inside port. This will be generated automatically.
$docker run --rm -ti -p 45678-p 45679--name echo-server ubuntu:14.04 bash
To get the automatically generated inside ports, use this command:
$docker port echo-server 45678/tcp -> 0.0.0.0:32769 45679/tcp -> 0.0.0.0:32768