Home Explore Blog CI



docker

3rd chunk of `content/get-started/docker-concepts/running-containers/multi-container-applications.md`
c2275fd6cd209f54f23480cb342e467479f49a14ef2e95b50000000100000a7d
    ```console
    $ docker run -d --name web2 -h web2 --network sample-app --network-alias web2 web
    ```
    
5. Start the Nginx container by running the following command:

    ```console
    $ docker run -d --name nginx --network sample-app  -p 80:80 nginx
    ```

     > [!NOTE]
     >
     > Nginx is typically used as a reverse proxy for web applications, routing traffic to backend servers. In this case, it routes to the Node.js backend containers (web1 or web2).


6.  Verify the containers are up by running the following command:

    ```console
    $ docker ps
    ```

    You will see output like the following: 

    ```text
    CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                NAMES
    2cf7c484c144   nginx     "/docker-entrypoint.…"   9 seconds ago        Up 8 seconds        0.0.0.0:80->80/tcp   nginx
    7a070c9ffeaa   web       "docker-entrypoint.s…"   19 seconds ago       Up 18 seconds                            web2
    6dc6d4e60aaf   web       "docker-entrypoint.s…"   34 seconds ago       Up 33 seconds                            web1
    008e0ecf4f36   redis     "docker-entrypoint.s…"   About a minute ago   Up About a minute   6379/tcp             redis
    ```

7. If you look at the Docker Desktop Dashboard, you can see the containers and dive deeper into their configuration.

   ![A screenshot of the Docker Desktop Dashboard showing multi-container applications](images/multi-container-apps.webp?w=5000&border=true)

8. With everything up and running, you can open [http://localhost](http://localhost) in your browser to see the site. Refresh the page several times to see the host that’s handling the request and the total number of requests:

    ```console
    web2: Number of visits is: 9
    web1: Number of visits is: 10
    web2: Number of visits is: 11
    web1: Number of visits is: 12
    ```

    > [!NOTE]
    >
    > You might have noticed that Nginx, acting as a reverse proxy, likely distributes incoming requests in a round-robin fashion between the two backend containers. This means each request might be directed to a different container (web1 and web2) on a rotating basis. The output shows consecutive increments for both the web1 and web2 containers and the actual counter value stored in Redis is updated only after the response is sent back to the client.

9. You can use the Docker Desktop Dashboard to remove the containers by selecting the containers and selecting the **Delete** button.

   ![A screenshot of Docker Desktop Dashboard showing how to delete the multi-container applications](images/delete-multi-container-apps.webp?border=true)

Title: Verifying and Accessing the Multi-Container Application
Summary
This section explains how to verify that all containers (Nginx, web1, web2, and Redis) are running using the `docker ps` command and through the Docker Desktop Dashboard. It then guides users on how to access the application via `http://localhost` in a web browser. It also describes how Nginx acts as a reverse proxy, distributing requests between the two backend web containers (web1 and web2) in a round-robin fashion. Finally, it explains how to use Docker Desktop to delete the containers.