Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Networking Host and Container Network Namespaces
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-networking-host-and-container-network-namespaces

Docker Docker Networking Host and Container Network Namespaces

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~2 min read

1. Core Command / Concept

This topic accomplishes understanding host and container network namespaces. docker network inspect.

2. Step-by-Step

  1. Check the default network namespace: docker network inspect bridge
    Output: Network ID, Name, and other details.
  2. Create a new network namespace: docker network create mynet
    Output: Network ID and Name.
  3. Inspect the new network namespace: docker network inspect mynet
    Output: Network ID, Name, and other details.
  4. ⚠️ Delete the new network namespace: docker network rm mynet
    Output: None.

3. Real Commands with Examples

  1. Purpose: Create a new network namespace for a web server.
    Command: docker network create --driver bridge mywebnet
    Flags: --driver bridge specifies the network driver.
  2. Purpose: Create a new network namespace for a database server.
    Command: docker network create --driver bridge mydbnet
    Flags: --driver bridge specifies the network driver.
  3. Purpose: Inspect the network namespace for a running container.
    Command: docker network inspect mycontainer
    Flags: None.

4. Common Errors

  1. Error: "Error response from daemon: Network not found".
    Why: The network namespace does not exist.
    Fix: docker network create mynet.
  2. Error: "Error response from daemon: Network has been allocated to user".
    Why: The network namespace is already in use.
    Fix: docker network rm mynet.
  3. Error: "Error response from daemon: Network is in use".
    Why: The network namespace is still in use.
    Fix: docker network rm mynet.

5. Quick Checks

  1. Situation: A container is not connected to a network namespace.
    Command: docker network inspect mycontainer
    Correct Response: Network ID and Name.
  2. Situation: A network namespace is not created.
    Command: docker network inspect mynet
    Correct Response: Error "Network not found".
  3. Situation: A network namespace is in use.
    Command: docker network inspect mynet
    Correct Response: Error "Network is in use".

6. Last-Minute Reference

  • Docker network driver: bridge, host, none.
  • Docker network create flags: --driver, --subnet.
  • Docker network inspect flags: None.
  • Docker network rm flags: None.
  • Docker network ls flags: -q, --filter.
  • Docker network prune flags: -f.
  • Docker network disconnect flags: None.
  • Docker network connect flags: None.
  • Docker network create options: --gateway, --subnet.
  • Docker network inspect output: Network ID, Name, IPAM, and other details.
  • Docker network rm deletes all networks.
  • Docker network prune deletes all unused networks.
  • Docker network disconnect disconnects a container from a network.
  • Docker network connect connects a container to a network.


ADVERTISEMENT