MODULE 7 · TOPIC 9 · VISUAL DEVOPS LAB

Introduction to Docker Networking

Containers communicate through network interfaces and Docker-managed networks. A user-defined bridge provides name-based resolution among attached containers. Port publishing maps host addresses and ports to container ports. Host and none network modes have different isolation behavior, and network membership does not replace application authentication.

Browser-based DevOps simulations. Commands, interfaces, logs and infrastructure states are illustrative; no Jenkins, Docker, Git hosting or Kubernetes operation is executed.

1. Bridge network — container to container

Containers on the same user-defined bridge can resolve each other by name and reach listening ports without publishing them to the host. Separate bridge networks are isolated by default, subject to routing and published-port configuration.

Why this example? Compare a client on the same bridge with a client on a different bridge.

Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
Why this step happens
See all steps in this scenario
    Commands and configuration
    Simulated terminal outputConsole
    Data operationsCompact blocks
    CurrentResultError / rejected

    Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.

    What this animation explains

    Containers on the same user-defined bridge can resolve each other by name and reach listening ports without publishing them to the host. Separate bridge networks are isolated by default, subject to routing and published-port configuration.

    Try and observe

    Watch name resolution and connectivity separately.

    2. Host port publishing

    The -p HOST:CONTAINER mapping forwards incoming connections to the container port. A loopback bind limits the intended host listener to local access. EXPOSE is metadata and does not by itself publish a port.

    Why this example? Compare a published host port with no published port.

    Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
    Why this step happens
    See all steps in this scenario
      Commands and configuration
      Simulated terminal outputConsole
      Data operationsCompact blocks
      CurrentResultError / rejected

      Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.

      What this animation explains

      The -p HOST:CONTAINER mapping forwards incoming connections to the container port. A loopback bind limits the intended host listener to local access. EXPOSE is metadata and does not by itself publish a port.

      Try and observe

      Inspect the route from browser to host port and then container port.

      3. Port conflicts and mappings

      A host IP and port binding cannot normally be allocated twice by different containers. Container internal ports may be identical because each has its own network namespace. Use distinct available host ports for two local web applications.

      Why this example? Compare two services requesting the same host port or separate host ports.

      Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
      Why this step happens
      See all steps in this scenario
        Commands and configuration
        Simulated terminal outputConsole
        Data operationsCompact blocks
        CurrentResultError / rejected

        Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.

        What this animation explains

        A host IP and port binding cannot normally be allocated twice by different containers. Container internal ports may be identical because each has its own network namespace. Use distinct available host ports for two local web applications.

        Try and observe

        Observe why the second container fails only in the duplicate host-binding scenario.

        4. Network modes — bridge, host and none

        Bridge mode uses Docker-managed network interfaces. Host mode on a supported Linux Engine shares the host network namespace, so published-port flags are unnecessary. None mode isolates external connectivity and retains loopback. Desktop behavior and support differ by platform.

        Why this example? Compare bridge, host and none modes for a simple diagnostic container.

        Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
        Why this step happens
        See all steps in this scenario
          Commands and configuration
          Simulated terminal outputConsole
          Data operationsCompact blocks
          CurrentResultError / rejected

          Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.

          What this animation explains

          Bridge mode uses Docker-managed network interfaces. Host mode on a supported Linux Engine shares the host network namespace, so published-port flags are unnecessary. None mode isolates external connectivity and retains loopback. Desktop behavior and support differ by platform.

          Try and observe

          Observe the distinct namespace and connectivity assumptions.

          5. Compose service discovery and database port

          Compose service names identify containers on the project network. Inside a Java API container, localhost means that container, not a separate database container. A JDBC URL should reference the database service name and its internal port when using the shared network.

          Why this example? Choose the database hostname used by a simulated Java service.

          Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
          Why this step happens
          See all steps in this scenario
            Commands and configuration
            Simulated terminal outputConsole
            Data operationsCompact blocks
            CurrentResultError / rejected

            Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.

            What this animation explains

            Compose service names identify containers on the project network. Inside a Java API container, localhost means that container, not a separate database container. A JDBC URL should reference the database service name and its internal port when using the shared network.

            Try and observe

            Compare failed localhost lookup with successful connection to db, assuming valid credentials and ready database.

            6. Attach and inspect networks

            docker network inspect reports network configuration and attached containers. docker network connect attaches an existing container to another network; disconnect removes that attachment. This can change which names and services are reachable.

            Why this example? Compare a diagnostic container before and after joining the shared lab network.

            Before you run: Choose a scenario and use Next step or Play. Read the diagram, command/configuration panel and simulated interface together. Code fragments require the indicated tools or existing project.
            Why this step happens
            See all steps in this scenario
              Commands and configuration
              Simulated terminal outputConsole
              Data operationsCompact blocks
              CurrentResultError / rejected

              Change inputs and step through the example. Simulated output. Exact logs, versions and UI appearance vary by installation.

              What this animation explains

              docker network inspect reports network configuration and attached containers. docker network connect attaches an existing container to another network; disconnect removes that attachment. This can change which names and services are reachable.

              Try and observe

              Inspect network membership and request result.

              Command and configuration reference

              Use these commands and settings with the corresponding installed tools in a disposable practice environment.

              Command / settingWhy and when to use it
              docker network create lab-netBridge network — container to container — Compare a client on the same bridge with a client on a different bridge.
              docker run -d --name web-lab -p 127.0.0.1:8080:80 nginx:alpineHost port publishing — Compare a published host port with no published port.
              docker run -d --name web-a -p 127.0.0.1:8080:80 nginx:alpinePort conflicts and mappings — Compare two services requesting the same host port or separate host ports.
              docker run --rm --network bridge alpine ip addrNetwork modes — bridge, host and none — Compare bridge, host and none modes for a simple diagnostic container.
              services:Choose the database hostname used by a simulated Java service.
              docker network inspect lab-netAttach and inspect networks — Compare a diagnostic container before and after joining the shared lab network.

              Worked practical examples

              Follow the procedures in an isolated practice environment. Configuration snippets may require an existing project, build tools, credentials, images or cluster objects as indicated.

              1. Connect two containers on a bridge

              Procedure

              1. Create an isolated practice network.
              2. Start nginx on that network and request it by name from a temporary Alpine container.
              3. Inspect network membership; stop and remove the lab web container when done.
              Code / configuration
              docker network create lab-net
              docker run -d --name api-lab --network lab-net nginx:alpine
              docker run --rm --network lab-net alpine wget -qO- http://api-lab
              docker network inspect lab-net
              Expected result: The temporary client receives nginx HTML using name resolution on the shared bridge.

              2. Publish a local web port

              Procedure

              1. Ensure 8080 is free and use a unique name.
              2. Publish only the host loopback address.
              3. Compare host URL with container internal port.
              Code / configuration
              docker run -d --name port-lab -p 127.0.0.1:8080:80 nginx:alpine
              docker port port-lab
              curl http://127.0.0.1:8080
              Expected result: Host port 8080 forwards to nginx port 80.

              Predict the outcome before you run

              Try answering these questions, then expand each answer and repeat the appropriate simulation.

              1. Predict the final state for Different bridge in “Bridge network — container to container”. Which operation explains it?

              Join intended network or use an authorized published endpoint Result: No HTTP response.

              2. Predict the final state for Not published in “Host port publishing”. Which operation explains it?

              Container may run internally, but host endpoint unavailable Result: Connection refused.

              3. Predict the final state for 8081 (separate) in “Port conflicts and mappings”. Which operation explains it?

              Both containers can listen on internal 80 Result: Two host endpoints.

              Hands-on practice and assessment

              Hands-on challenge

              Create an isolated practice bridge network, run an nginx container and test it from a second container. Publish a loopback host port only when host access is required.

              Edit this command/configuration scratchpad. Review prerequisites and run only in your own isolated practice environment; the browser never executes commands.

              Quick assessment

              Official documentation

              Use the documentation for your installed tool versions and platform.

              https://docs.docker.com/engine/network/

              https://docs.docker.com/engine/network/drivers/bridge/

              https://docs.docker.com/engine/network/port-publishing/

              https://docs.docker.com/desktop/features/networking/

              Key points and real tool notes

              Use a local disposable practice environment and verify the active context, account, repository and names before running commands. Examples use Java 21, Maven 3.9, Jenkins Pipeline, Docker Engine and standard Kubernetes APIs. Logs and interfaces are educational reconstructions; versions, permissions, resources and real results can differ. No real deployments, credentials or network operations run in this page.