What is container to container communication in Docker?
It is the process where two or more Docker containers exchange data or messages directly with each other.
Click to reveal answer
beginner
How do Docker containers communicate by default when on the same user-defined network?
They can communicate using container names as hostnames because Docker's user-defined networks provide automatic DNS resolution.
Click to reveal answer
beginner
What Docker command creates a user-defined network for container communication?
docker network create my-network
Click to reveal answer
intermediate
Why is it recommended to use user-defined bridge networks for container communication instead of the default bridge network?
User-defined bridge networks provide better isolation, automatic DNS resolution, and easier container name communication compared to the default bridge network.
Click to reveal answer
intermediate
How can you allow two containers to communicate if they are on different Docker networks?
You can connect a container to multiple networks using 'docker network connect' or create a shared network both containers join.
Click to reveal answer
Which Docker network type allows containers to communicate using container names as hostnames?
ANone network
BHost network
CDefault bridge network
DUser-defined bridge network
✗ Incorrect
User-defined bridge networks provide automatic DNS resolution, allowing containers to use container names to communicate.
What command creates a new Docker network named 'app-net'?
Adocker create network app-net
Bdocker network create app-net
Cdocker network new app-net
Ddocker create app-net network
✗ Incorrect
The correct syntax to create a network is 'docker network create '.
If two containers are on the default bridge network, how do they communicate?
AUsing IP addresses only
BUsing container names as hostnames
CThey cannot communicate
DUsing host machine's IP
✗ Incorrect
On the default bridge network, containers must use IP addresses to communicate because DNS resolution is not provided.
How can you connect an existing container to a new network?
Hint: Remember: 'docker network create' is the correct syntax [OK]
Common Mistakes:
Using 'docker create network' instead of 'docker network create'
Using 'docker network new' which is invalid
Trying 'docker network add' which does not exist
3. Given two containers web and db connected to the same user-defined network, what will be the output of docker exec web ping -c 1 db if db is running and reachable?
medium
A. ping: unknown host db
B. PING db (172.18.0.2): 56 data bytes\n64 bytes from 172.18.0.2: icmp_seq=0 ttl=64 time=0.123 ms\n\n--- db ping statistics ---\n1 packets transmitted, 1 packets received, 0% packet loss
C. connect: Network is unreachable
D. Request timed out
Solution
Step 1: Understand container DNS resolution on user-defined networks
Containers on the same user-defined network can resolve each other by container name, so 'db' resolves to its IP.
Step 2: Predict ping command output
Since 'db' is running and reachable, ping will succeed with a response showing bytes received and 0% packet loss.
Final Answer:
Successful ping output with 1 packet transmitted and received -> Option B
Quick Check:
Same network + running container = ping success [OK]
Hint: Ping container name on same network to test connectivity [OK]
Common Mistakes:
Assuming default bridge network supports container name resolution
Expecting ping to fail without port mapping
Confusing network unreachable with DNS resolution failure
4. You created two containers on a user-defined network but web cannot reach db. Which command helps you debug the network connectivity issue?
medium
A. docker ps -a
B. docker container logs web
C. docker network inspect mynetwork
D. docker volume ls
Solution
Step 1: Identify the tool to check network details
docker network inspect shows connected containers and network settings, useful for debugging connectivity.
Step 2: Evaluate other commands
docker container logsdocker ps -a lists containers; docker volume ls lists volumes, none show network details.
Final Answer:
docker network inspect mynetwork -> Option C
Quick Check:
Inspect network to debug connectivity [OK]
Hint: Use 'docker network inspect' to check container connections [OK]
Common Mistakes:
Checking container logs instead of network info
Listing volumes which are unrelated
Assuming 'docker ps' shows network details
5. You want two containers, app and cache, to communicate securely without exposing ports to the host. Which approach achieves this?
hard
A. Connect both containers to the same user-defined network and communicate via container names
B. Expose ports on both containers and use localhost to connect
C. Use host networking mode for both containers
D. Share a volume and write/read data files for communication
Solution
Step 1: Understand secure container communication
Using a user-defined network allows containers to communicate internally without exposing ports to the host, keeping communication private.
Step 2: Evaluate other options for security
Exposing ports or using host networking exposes services outside the host or risks port conflicts. Sharing volumes is not network communication.
Final Answer:
Connect both containers to the same user-defined network and communicate via container names -> Option A
Quick Check:
User-defined network keeps communication internal and secure [OK]
Hint: Use user-defined network to avoid exposing ports externally [OK]
Common Mistakes:
Exposing ports unnecessarily to the host
Using host network mode which is less secure
Confusing volume sharing with network communication
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.