Bird
Raised Fist0
Dockerdevops~20 mins

Why custom networks matter in Docker - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Docker Network Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use custom Docker networks?

Which of the following is the main reason to create a custom Docker network instead of using the default bridge network?

ATo isolate containers and control communication between them
BTo increase container CPU usage automatically
CTo enable containers to run without Docker installed
DTo reduce the size of Docker images
Attempts:
2 left
💡 Hint

Think about how containers talk to each other and how you can control that.

💻 Command Output
intermediate
2:00remaining
Output of listing Docker networks

What is the output of the command docker network ls after creating a custom network named my_custom_net?

Docker
docker network create my_custom_net
docker network ls
A
NETWORK ID   NAME           DRIVER    SCOPE
<id>         bridge         bridge    local
<id>         host           host      local
<id>         none           null      local
<id>         my_custom_net  bridge    local
BError: network my_custom_net not found
C
NETWORK ID   NAME           DRIVER    SCOPE
<id>         bridge         overlay   local
<id>         my_custom_net  host      local
DNo networks found
Attempts:
2 left
💡 Hint

Custom networks appear alongside default networks with the same driver unless specified otherwise.

🔀 Workflow
advanced
2:00remaining
Connecting containers to a custom network

You have two containers: app and db. You want them to communicate securely using a custom network named secure_net. Which sequence of commands correctly sets this up?

A
docker network create secure_net
docker network connect secure_net app
docker network connect secure_net db
B
docker network create secure_net
docker run --network=secure_net app
docker run --network=secure_net db
C
docker network create secure_net
docker run app
docker run db
D
docker network create secure_net
docker network disconnect bridge app
docker network disconnect bridge db
docker network connect secure_net app
docker network connect secure_net db
Attempts:
2 left
💡 Hint

Think about how to start containers directly attached to a network.

❓ Troubleshoot
advanced
2:00remaining
Why can't containers communicate on default bridge network?

You started two containers on the default bridge network but they cannot ping each other by container name. What is the most likely reason?

ADocker daemon is not running
BContainers must be on the host network to communicate
CThe default bridge network does not support automatic DNS resolution between containers
DContainers need to share the same image to communicate
Attempts:
2 left
💡 Hint

Think about how container names resolve to IP addresses on different networks.

✅ Best Practice
expert
2:00remaining
Best practice for Docker network security

Which practice best improves security when using Docker networks in a multi-container application?

ARun all containers with host networking to improve performance
BUse the default bridge network for all containers to simplify setup
CDisable Docker networking to prevent all container communication
DCreate separate custom networks for different application components and restrict container connections accordingly
Attempts:
2 left
💡 Hint

Think about isolating parts of your app to limit access.

Practice

(1/5)
1. Why is it important to create a custom Docker network instead of using the default network?
easy
A. It allows containers to communicate securely and isolate traffic.
B. It automatically increases container CPU usage.
C. It disables container communication completely.
D. It removes the need for container images.

Solution

  1. Step 1: Understand default network limitations

    The default Docker network allows basic communication but lacks isolation and security controls.
  2. Step 2: Benefits of custom networks

    Custom networks let you isolate containers and control which containers can talk to each other securely.
  3. Final Answer:

    It allows containers to communicate securely and isolate traffic. -> Option A
  4. Quick Check:

    Custom networks improve security and isolation = B [OK]
Hint: Custom networks isolate and secure container communication [OK]
Common Mistakes:
  • Thinking default network is always secure
  • Believing custom networks increase CPU usage
  • Assuming custom networks disable communication
2. Which command correctly creates a new custom Docker network named my-net?
easy
A. docker network create my-net
B. docker create network my-net
C. docker network new my-net
D. docker net create my-net

Solution

  1. Step 1: Recall Docker network creation syntax

    The correct command to create a network is docker network create <name>.
  2. Step 2: Check each option

    Only docker network create my-net matches the correct syntax exactly.
  3. Final Answer:

    docker network create my-net -> Option A
  4. Quick Check:

    Correct command syntax = D [OK]
Hint: Use 'docker network create' to make custom networks [OK]
Common Mistakes:
  • Swapping 'create' and 'network' order
  • Using 'new' instead of 'create'
  • Shortening 'network' to 'net' incorrectly
3. Given this Docker command sequence:
docker network create app-net
docker run -d --name web --network app-net nginx
docker run -d --name db --network app-net mysql
What will happen if the web container tries to connect to db using the container name?
medium
A. The connection will fail because containers need IP addresses.
B. The connection will succeed because both containers share the custom network.
C. The connection will fail because default network is required.
D. The connection will succeed only if ports are exposed.

Solution

  1. Step 1: Understand container networking on custom networks

    Containers on the same custom network can reach each other by container name as DNS resolves names automatically.
  2. Step 2: Analyze the command setup

    Both web and db are on app-net, so web can connect to db using its name.
  3. Final Answer:

    The connection will succeed because both containers share the custom network. -> Option B
  4. Quick Check:

    Same custom network enables name-based communication = A [OK]
Hint: Containers on same custom network communicate by name [OK]
Common Mistakes:
  • Thinking IP addresses are always needed
  • Assuming default network is required for name resolution
  • Believing ports must be exposed for internal communication
4. You created a custom network with docker network create my-net and started two containers attached to it. But they cannot communicate by container name. What is the most likely cause?
medium
A. Docker daemon is not running.
B. The network was created with the wrong driver.
C. Containers need to be restarted twice.
D. Containers were started without specifying the network.

Solution

  1. Step 1: Check container network attachment

    Containers must be started with --network my-net to join the custom network.
  2. Step 2: Identify common mistake

    If containers are not attached to the custom network, they cannot resolve each other's names.
  3. Final Answer:

    Containers were started without specifying the network. -> Option D
  4. Quick Check:

    Containers must join network explicitly = C [OK]
Hint: Always use --network to attach containers to custom networks [OK]
Common Mistakes:
  • Assuming network auto-attachment
  • Blaming network driver without checking container config
  • Restarting containers unnecessarily
5. You want to run three containers: frontend, backend, and database. You want frontend to communicate only with backend, and backend to communicate with database, but frontend should NOT talk directly to database. How can you achieve this using Docker custom networks?
hard
A. Run all containers on one custom network and rely on container names to restrict access.
B. Attach all containers to the default network and use firewall rules inside containers.
C. Create two custom networks: one for frontend-backend, another for backend-database, and attach containers accordingly.
D. Use host networking mode for all containers.

Solution

  1. Step 1: Understand network isolation

    Docker networks isolate containers; containers on different networks cannot communicate unless attached to both.
  2. Step 2: Design network setup

    Create two networks: one connecting frontend and backend, another connecting backend and database. Attach frontend and backend to first network, backend and database to second.
  3. Step 3: Resulting communication

    Frontend can reach backend, backend can reach database, but frontend cannot reach database directly.
  4. Final Answer:

    Create two custom networks: one for frontend-backend, another for backend-database, and attach containers accordingly. -> Option C
  5. Quick Check:

    Separate networks control container communication = A [OK]
Hint: Use multiple custom networks to control container access [OK]
Common Mistakes:
  • Using one network expecting access control by names
  • Relying on default network for isolation
  • Using host networking which disables isolation
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard