How to Access Docker container from another container by name

Task:

Create custom network with default bridge driver named as my-custom-net.
Create two container named as web1 and test1 with custom network i.e my-custom-net.
Access the container web1 from test1 using the curl command. 

1. Create a custom network with the default driver.

#docker network create --driver bridge my-custom-net                                       

2. Create Nginx Container with a custom network.

#docker container run -itd --name web1 --network my-custom-net nginx             

3. Create another container with to test Nginx container

 #docker container run -itd --name test1 --network my-custom-net                      pranavdhopey/goinit_hub:curl                                                                           

Note: pranavdhopey/goinit_hub:curl is my own image with a curl package installed on alpine base image.

4. Now check whether we are able to access the web page from other container.

#docker container exec test1 curl web1:80                                                        


By above screenshot, we can see that we are able to access web1 from test1 container using name. 













No comments:

Post a Comment