Working With Container Linking
Container Linking allows multiple containers to link with each other. It is a better option than exposing ports. Let’s go step by step and learn how it works.
- Download the Jenkins image, if it is not already present, using the Jenkins pull command.
sudo docker jenkins pull
- Once the image is available, run the container, but this time, you can specify a name to the container by using the –-name option. This will be our source container.
sudo docker run --name=jenkinsa -d jenkins
- Next, it is time to launch the destination container, but this time, we will link it with our source container. For our destination container, we will use the standard Ubuntu image.
sudo docker run --name=reca --link=jenkinsa:alias-src -it ubuntu:latest /bin/bash
When you do a docker ps, you will see both the containers running.
- Now, attach to the receiving container.
sudo docker attach reca
- Then run the env command. You will notice new variables for linking with the source container.