Outline

Container Communication

You can use the network if you need your containers to communicate.

To try this, create two containers by running the commands docker container run -it --rm --name c1 alpine sh and docker container run -it --rm --name c2 alpine sh.

You can see that they each have unique ip addresses using the command ifconfig eth0.

You can reach c2 from c1 by pinging it's ip address using the command ping [C2-IP-ADDRESS].

You can also refer to the container by it's name instead of it's ip address. Do this by first quitting the c2 container and restarting it with the command docker container run -it --rm --name c2 --link c1 alpine sh. The --link flag after the name of the container is the important change here. It allows you to talk to c1 by using it's container name.

Note that links are deprecated but they are easy to use and many docker examples still reference them. The modern way to connect containers is shown in the next video.

 

I finished! On to the next chapter