0
0
Dockerdevops~30 mins

Container to container communication in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Container to container communication
📖 Scenario: You are setting up two Docker containers that need to talk to each other on the same network. One container will run a simple web server, and the other will send a request to that server.
🎯 Goal: Build two Docker containers connected on the same network so that one container can successfully send a request to the other container's web server.
📋 What You'll Learn
Create a Docker network called my_network
Create a container named web_server running an nginx server connected to my_network
Create a container named client connected to my_network
From the client container, send a request to the web_server container using its container name
💡 Why This Matters
🌍 Real World
Containers often need to talk to each other in microservices or multi-component apps. Using Docker networks allows this communication easily.
💼 Career
Understanding container networking is key for DevOps roles managing containerized applications and orchestrations.
Progress0 / 4 steps
1
Create a Docker network
Create a Docker network called my_network using the docker network create command.
Docker
Need a hint?

Use docker network create my_network to make a new network.

2
Run a web server container on the network
Run a container named web_server using the nginx image. Connect it to the my_network network using the --network option.
Docker
Need a hint?

Use docker run -d --name web_server --network my_network nginx to start the web server container.

3
Run a client container on the network
Run a container named client using the alpine image. Connect it to the my_network network using the --network option. Start it with an interactive shell sh.
Docker
Need a hint?

Use docker run -it --name client --network my_network alpine sh to start the client container with a shell.

4
Send a request from client to web_server
Inside the client container shell, install curl using apk add curl. Then send a request to http://web_server using curl and print the output.
Docker
Need a hint?

Use apk add curl to install curl, then curl http://web_server to send the request.