Container networking is the way containers communicate with each other and with the outside world, allowing them to send and receive data over networks.
Click to reveal answer
beginner
Name a common network mode used by containers.
Bridge network mode is common; it creates a private network internal to the host where containers can communicate.
Click to reveal answer
beginner
What does port mapping do in container networking?
Port mapping connects a port on the host machine to a port inside the container, allowing external access to container services.
Click to reveal answer
intermediate
How does the 'host' network mode differ from 'bridge' mode?
In 'host' mode, the container shares the host's network stack directly, so no isolation exists. In 'bridge' mode, containers have their own network namespace.
Click to reveal answer
beginner
Why is container networking important for running nginx inside a container?
Because nginx needs to listen on network ports to serve web pages, container networking allows nginx to receive requests and send responses properly.
Click to reveal answer
Which network mode isolates container networking from the host?
AHost
BBridge
CNone
DOverlay
✗ Incorrect
Bridge mode creates a private network for containers, isolating them from the host network.
What does port mapping allow you to do?
AConnect container ports to host ports
BShare container files
CRun multiple containers
DCreate container images
✗ Incorrect
Port mapping connects a container's port to a port on the host, enabling external access.
In container networking, what is a 'network namespace'?
AA type of container
BA container image
CA storage volume
DA separate network environment for containers
✗ Incorrect
A network namespace isolates the container's network stack from others.
Which command option maps port 80 of an nginx container to port 8080 on the host?
Adocker run -p 8080:80 nginx
Bdocker run -p 80:8080 nginx
Cdocker run --net=host nginx
Ddocker run -v 8080:80 nginx
✗ Incorrect
The syntax -p hostPort:containerPort maps host port 8080 to container port 80.
Why might you use the 'host' network mode?
ATo create a private network bridge
BTo isolate container networking
CFor better network performance without isolation
DTo share files between containers
✗ Incorrect
Host mode shares the host network stack, improving performance but removing isolation.
Explain how port mapping works in container networking and why it is useful for running nginx.
Think about how a web browser reaches nginx inside a container.
You got /3 concepts.
Describe the difference between bridge and host network modes in containers.
Consider how containers see the network in each mode.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of container networking in Docker?
easy
A. To allow containers to communicate with each other
B. To increase container storage space
C. To speed up container startup time
D. To change container CPU limits
Solution
Step 1: Understand container networking basics
Container networking connects containers so they can share data and services.
Step 2: Identify the purpose
The main goal is to enable communication between containers.
Final Answer:
To allow containers to communicate with each other -> Option A
Quick Check:
Container networking = communication [OK]
Hint: Networking means containers talk to each other [OK]
Common Mistakes:
Confusing networking with storage or CPU settings
Thinking networking speeds up container startup
Assuming networking changes resource limits
2. Which Docker command creates a new custom network for containers?
easy
A. docker create mynet network
B. docker network create mynet
C. docker network new mynet
D. docker create network mynet
Solution
Step 1: Recall Docker network creation syntax
The correct command is docker network create <name>.
Step 2: Match the options
Only docker network create mynet matches the correct syntax exactly.
Final Answer:
docker network create mynet -> Option B
Quick Check:
docker network create = create network [OK]
Hint: Remember: 'docker network create' makes networks [OK]
Common Mistakes:
Swapping order of 'create' and 'network'
Using 'new' instead of 'create'
Adding extra words after network name
3. What will be the result of running this command?
docker run --network mynet nginx
medium
A. The nginx container connects to the 'mynet' network
B. The nginx container creates a new network named 'mynet'
C. The command fails because '--network' is invalid
D. The container runs without any network connection
Solution
Step 1: Understand the '--network' flag
The flag connects the container to an existing network named 'mynet'.
Step 2: Analyze the command effect
The command runs nginx container attached to 'mynet' network.
Final Answer:
The nginx container connects to the 'mynet' network -> Option A
Quick Check:
--network attaches container to network [OK]
Hint: Use --network to join existing networks [OK]
Common Mistakes:
Thinking it creates a new network
Believing '--network' is invalid syntax
Assuming container runs without network
4. You ran docker run --network mynet nginx but got an error: "network mynet not found". What is the likely fix?
medium
A. Restart Docker service and try again
B. Remove the '--network' option from the command
C. Create the network first using docker network create mynet
D. Use docker network connect mynet nginx instead
Solution
Step 1: Understand the error message
The error means the network 'mynet' does not exist yet.
Step 2: Fix by creating the network
Use docker network create mynet to create it before running the container.
Final Answer:
Create the network first using docker network create mynet -> Option C
Quick Check:
Network must exist before use [OK]
Hint: Create network before attaching containers [OK]
Common Mistakes:
Skipping network creation
Trying to connect without network existing
Assuming restart fixes network errors
5. You want two nginx containers to communicate using a custom network. Which steps correctly set this up?
hard
A. Run containers normally, then use docker network connect mynet <container> without creating network
B. Run containers with --link mynet option to connect them
C. Create network with docker create network mynet, then run containers without network option
D. Create network with docker network create mynet, then run both containers with --network mynet
Solution
Step 1: Create a custom network
Use docker network create mynet to make a network for containers.
Step 2: Run containers attached to the network
Start both nginx containers with --network mynet to connect them.
Final Answer:
Create network with docker network create mynet, then run both containers with --network mynet -> Option D
Quick Check:
Create network + attach containers = communication [OK]
Hint: Create network first, then run containers on it [OK]
Common Mistakes:
Using wrong command to create network
Not attaching containers to the network
Using deprecated --link option
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.