Bird
Raised Fist0
Dockerdevops~10 mins

Creating custom bridge networks in Docker - Visual Walkthrough

Choose your learning style10 modes available
Process Flow - Creating custom bridge networks
Start
↓
Run: docker network create --driver bridge my_bridge
↓
Docker creates new bridge network
↓
Network available for containers
↓
Containers connect to custom bridge
↓
End
This flow shows how Docker creates a custom bridge network and how containers can connect to it.
Execution Sample
Docker
docker network create --driver bridge my_bridge

docker network ls

docker run -dit --name container1 --network my_bridge alpine sh
Creates a custom bridge network, lists networks, and runs a container connected to the custom bridge.
Process Table
StepCommandActionResult
1docker network create --driver bridge my_bridgeCreate a new bridge network named 'my_bridge'Network 'my_bridge' created
2docker network lsList all Docker networksShows 'my_bridge' among default networks
3docker run -dit --name container1 --network my_bridge alpine shRun container 'container1' attached to 'my_bridge'Container 'container1' runs connected to 'my_bridge'
4docker network inspect my_bridgeInspect network detailsShows container1 connected to 'my_bridge'
5docker network create --driver bridge my_bridgeTry to create network with existing nameError: network with name 'my_bridge' already exists
💡 Execution stops after network creation and container run; duplicate network creation fails.
Status Tracker
VariableStartAfter Step 1After Step 3Final
Networksdefault, bridge, host, nonedefault, bridge, host, none, my_bridgedefault, bridge, host, none, my_bridgedefault, bridge, host, none, my_bridge
Containersnonenonecontainer1 (on my_bridge)container1 (on my_bridge)
Key Moments - 2 Insights
Why does the second 'docker network create' command fail?
Because a network named 'my_bridge' already exists as shown in execution_table step 5, Docker prevents duplicate network names.
How do we know the container is connected to the custom bridge network?
In execution_table step 4, inspecting 'my_bridge' shows 'container1' connected, confirming the container uses the custom network.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of step 2?
AShows 'my_bridge' among default networks
BCreates a new container
CDeletes the network
DFails with error
💡 Hint
Check the 'Result' column in execution_table row for step 2
At which step does the container 'container1' start running?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the 'Action' and 'Result' columns for when the container is created
If you rename the network in step 1 to 'custom_net', what changes in the execution table?
AThe container connects to default bridge
BThe container name changes
CThe network name in step 1 and 2 results changes to 'custom_net'
DNo changes at all
💡 Hint
Focus on the network name in the 'Command' and 'Result' columns of steps 1 and 2
Concept Snapshot
Create a custom bridge network with:
  docker network create --driver bridge <name>
List networks:
  docker network ls
Run container on custom network:
  docker run --network <name> ...
Avoid duplicate network names to prevent errors.
Full Transcript
This lesson shows how to create a custom Docker bridge network named 'my_bridge'. First, the command 'docker network create --driver bridge my_bridge' creates the network. Then, 'docker network ls' lists all networks including the new one. Next, a container named 'container1' is run attached to 'my_bridge' using 'docker run -dit --name container1 --network my_bridge alpine sh'. Inspecting the network confirms the container is connected. Trying to create the same network again causes an error because the name is already taken. Variables tracked include the list of networks and containers connected. Key points include understanding why duplicate network creation fails and how to verify container network connection. The quizzes test understanding of the execution steps and effects of changing network names.

Practice

(1/5)
1. What is the main purpose of creating a custom bridge network in Docker?
easy
A. To increase the CPU usage of containers
B. To allow containers to communicate privately and securely
C. To automatically update container images
D. To create a backup of container data

Solution

  1. Step 1: Understand Docker networking basics

    Docker uses networks to connect containers. The default bridge network is shared and less secure.
  2. Step 2: Purpose of custom bridge networks

    Custom bridge networks isolate containers, allowing private and secure communication between them.
  3. Final Answer:

    To allow containers to communicate privately and securely -> Option B
  4. Quick Check:

    Custom bridge network = private container communication [OK]
Hint: Custom bridge = private container communication [OK]
Common Mistakes:
  • Thinking custom bridge increases CPU usage
  • Confusing network creation with image updates
  • Assuming it creates data backups
2. Which of the following is the correct command to create a custom bridge network named my_bridge?
easy
A. docker network create --driver bridge my_bridge
B. docker create network bridge my_bridge
C. docker network new --type bridge my_bridge
D. docker bridge create network my_bridge

Solution

  1. Step 1: Recall Docker network creation syntax

    The correct syntax is docker network create --driver bridge NETWORK_NAME.
  2. Step 2: Match the command with the syntax

    docker network create --driver bridge my_bridge matches the correct syntax exactly for creating a bridge network named my_bridge.
  3. Final Answer:

    docker network create --driver bridge my_bridge -> Option A
  4. Quick Check:

    Correct syntax = docker network create --driver bridge [OK]
Hint: Use 'docker network create --driver bridge NAME' [OK]
Common Mistakes:
  • Using wrong command order
  • Missing --driver flag
  • Using 'new' or 'create' incorrectly
3. Given the command docker network create --driver bridge isolated_net, what will be the output of docker network ls related to this network?
medium
A. No change; the network list remains the same
B. An error message saying 'driver not found' will appear
C. The default bridge network will be removed
D. A new network named 'isolated_net' with driver 'bridge' will appear in the list

Solution

  1. Step 1: Understand the effect of the create command

    The command creates a new bridge network named 'isolated_net'.
  2. Step 2: Check the network list after creation

    Running docker network ls shows all networks including the newly created 'isolated_net' with driver 'bridge'.
  3. Final Answer:

    A new network named 'isolated_net' with driver 'bridge' will appear in the list -> Option D
  4. Quick Check:

    New bridge network appears in list [OK]
Hint: New bridge network shows in 'docker network ls' [OK]
Common Mistakes:
  • Expecting an error for valid driver
  • Thinking default bridge is removed
  • Assuming no change in network list
4. You ran docker network create --driver bridge without specifying a network name. What is the likely result?
medium
A. Docker creates a network named 'bridge' by default
B. Docker creates a network with a random generated name
C. Docker throws an error about missing network name
D. Docker creates the default bridge network again

Solution

  1. Step 1: Check required arguments for network creation

    The docker network create command requires a network name after options.
  2. Step 2: Result of missing network name

    Omitting the network name causes Docker to throw an error indicating the missing argument.
  3. Final Answer:

    Docker throws an error about missing network name -> Option C
  4. Quick Check:

    Missing name causes error [OK]
Hint: Always specify network name after options [OK]
Common Mistakes:
  • Assuming Docker auto-generates network name
  • Thinking 'bridge' is default name created
  • Confusing with default bridge network
5. You want two containers to communicate only with each other and not with other containers on the host. Which steps correctly create and use a custom bridge network named private_net?
hard
A. Create network with docker network create --driver bridge private_net and run containers with --network private_net
B. Run containers with --link option without creating a network
C. Use default bridge network and assign static IPs manually
D. Create network with docker network create private_net without specifying driver

Solution

  1. Step 1: Create a custom bridge network

    Use docker network create --driver bridge private_net to create an isolated network.
  2. Step 2: Run containers attached to this network

    Start containers with --network private_net so they communicate only within this network.
  3. Final Answer:

    Create network with 'docker network create --driver bridge private_net' and run containers with '--network private_net' -> Option A
  4. Quick Check:

    Custom bridge + --network = isolated container communication [OK]
Hint: Create bridge network then run containers with --network [OK]
Common Mistakes:
  • Using --link which is deprecated
  • Relying on default bridge for isolation
  • Omitting --driver option causing default driver
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