Getting Started with Docker Networks

    Inspecting Docker’s Default Networks

    When Docker is installed, it automatically creates several default networks. List them using:

    docker network ls
    Docker network list

    The bridge network is the default for containers. host shares the host’s stack, and none provides complete isolation. For most local development, you'll live in the bridge world. Let's explore that.

    The Default Bridge: What You Need to Understand#

    When you run a container without specifying a network, Docker places it on the default bridge network. Here's the catch: containers on the default bridge can only communicate via IP addresses, not container names. Let’s understand with example, we will use two containers with alpine image for this. These are tiny and comes with the ping utility ready to go. We'll name them c1 and c2.

    Step 1: Creating Containers

    # Start the first container in the background docker run -dit --name c1 alpine sh # Start the second container in the background docker run -dit --name c2 alpine sh

    When you run docker run -dit alpine sh:

    1. d: You start it and keep working in your host terminal.
    2. i and t: You ensure that the sh (shell) process inside Alpine stays alive and "waiting" for you.

    If you ran docker run -d alpine sh without the -it, the container would start, realize no one is talking to it, and immediately exit. The -it keeps that shell "alive" in the background.

     

    Step 2: Find the IP Address

    Now, let's find the actual IP address Docker assigned to c1 and c2. By using inspect command

    #To get detail network infromation of the container you can use the below command docker inspect c1 #As we only want to know the IPAddress, we will use grep to filter the field docker inspect c1 | grep "IPAddress" docker inspect c2 | grep "IPAddress"
    Inspect docker containers

     

    Step 3: Let's try to ping the containers

    Let’s hop into c1 and try to reach c2 by its name.

    docker exec -it c1 ping -c 3 c2

    Expected Result: You will see an error like ping: bad address 'c2'. This confirms that the default bridge doesn't know who "c2" is, which we already read in the beginning of this section.

     

    Step 4: Now let's ping c2 using its ip-address

    docker exec -it c1 ping -c 3 172.17.0.3
    Ping between two containers

    Expected Result: Success! The packets will travel through the virtual bridge (docker0) because the routing is there, even if the "address book" (DNS) is not.

    Port Mapping: The Host vs Container#

    By default, Docker containers aren’t reachable from outside the host. To allow external systems to access a containerized service we need to map the container port to a port on host machine.

    Syntax: docker run -p <Host-port>:<Container-port> <container-name>

    #Syntax: docker run -p 8080:80 nginx

    Now this container is accessible on http://localhost:8080

    Docker command to port forward

     

    Port forwarding information

     

    Accessing the Nginx web server from local machine

    Some extra commands#

    1. To disconnect/remove a container from a network use docker network disconnect <network-name> <container-name-or-id>
    2. You can remove a Docker network using docker network rm <network-name>
    3. To remove the unused docker networks you can use docker network prune

    Conclusion#

    Understanding Docker’s default networking behavior is essential for managing container communication effectively. The default bridge network allows containers to communicate using IP addresses, while port mapping enables external access to containerized services. By inspecting networks, identifying container IPs, and configuring port mappings, developers can control how containers interact internally and with the host system, forming the foundation for more advanced Docker networking setups.

    Want to Master Spring Boot and Land Your Dream Job?

    Struggling with coding interviews? Learn Data Structures & Algorithms (DSA) with our expert-led course. Build strong problem-solving skills, write optimized code, and crack top tech interviews with ease

    Learn more

    Last updated on Mar 16, 2026

    Was it helpful?

    Subscribe to our newsletter

    Read articles from Coding Shuttle directly inside your inbox. Subscribe to the newsletter, and don't miss out.