# Inter-Container Communication Using Docker Bridge Network on AWS EC2

### **Step 1: Log in to Your AWS Account and Access EC2**

1. Go to [https://aws.amazon.com](https://aws.amazon.com) and sign in to your AWS Management Console.
    
2. From the AWS services dashboard, search for and open **EC2 (Elastic Compute Cloud)**.
    
3. You will be directed to the EC2 dashboard where you can launch and manage instances.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748243148463/8e49764a-5086-4784-8cc6-a4a88e9353c3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748243182440/844320c5-88ff-4238-851e-a20776ecaf78.png align="center")

Proceed to assign a name to your EC2 instance for easy identification

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748243279712/f4f2621c-ffff-4458-aa56-75988087ae6f.png align="center")

For this mini project, I will be using Amazon Linux as the AMI. However, you may choose a different AMI based on your preference.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748243443359/67c90249-4cca-4277-98c0-5a6d4e10d46a.png align="center")

Select an instance type; for this mini project, I will use **t2.micro** (Free Tier eligible), which is sufficient for our requirements

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748243624215/2964cc34-ea88-491e-859c-3f0ab03673c9.png align="center")

If you don’t have a key pair yet, create a new one now. Alternatively, you can use an existing key pair from your previous AWS setups

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748243792823/bb81f5fe-3ec7-4294-8458-00144029983e.png align="center")

For network configuration, I will create a new security group tailored to this mini project’s needs, including firewall rules to allow all IPv4 ICMP traffic. SSH access will remain allowed by default.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244011127/e6ef0888-b87e-4ebe-8671-befc0ded69b4.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244043293/174e7f74-4602-43e5-b7b6-b873e8988be8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244086898/e41af9ab-cbaa-49ab-a5b9-11a4853e4c72.png align="center")

Review the summary carefully, and if you’re satisfied with the EC2 configuration, proceed by clicking ‘Launch Instances.’

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244189573/bc5693ff-1874-4785-9705-e15a1da58a08.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244208261/258251d2-e9d5-4c6f-90eb-86719cbf7bd8.png align="center")

Click on ‘Instances’ to be redirected to the Instances tab

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244267192/457f90d9-047b-4480-9350-c381440662af.png align="center")

In the top right corner, click the ‘Connect’ button to establish a connection to your EC2 instance. Several connection methods are available; I will use the EC2 Instance Connect feature.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244353407/60ea1e65-ad05-44be-9647-ef1580be9f22.png align="center")

Go ahead and click on connect button

Alternatively, you can use an SSH client by first setting the correct file permissions for your key pair using the following command:

```bash
sudo chmod 400 "26052025.pem"
```

Then, copy and paste the SSH command into your terminal to access your EC2 instance. In my case, the command is:

```bash
ssh -i "26052025.pem" ec2-user@ec2-3-82-211-40.compute-1.amazonaws.com
```

Using the EC2 Instance Connect feature, I have successfully accessed my EC2 instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244609065/3e3cc853-ae37-4a87-950b-f935fd1f96ba.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244842891/6474a785-c200-4c81-8c0e-9d6c2a118c86.png align="center")

```bash
sudo su
```

Gain root access to simplify the execution of commands. It’s also a good practice to update your system packages to their latest versions

```bash
yum update -y
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244886316/ebbb7738-74b7-4394-ba5f-5c77d1f86be8.png align="center")

Now, let's proceed to install Docker on this EC2 instance using the following command:

```bash
yum install docker -y
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748244969585/46151844-9f88-4754-9160-695ee4ff5363.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245394975/d17beb13-ef0b-4db6-831c-6b7a595c4a3a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245439318/f20801cc-7279-455d-b75f-86004557cfe9.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245493087/748fccd4-530c-4016-9e44-148628d97d7c.png align="center")

Once Docker is installed, verify the installed version by running the following command:

```bash
docker --version
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245591994/ecba4ff3-a915-4283-bb58-1b27607a7aee.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245662831/9eede17f-8b6d-4b38-934e-be302705342d.png align="center")

```bash
sudo su
```

```bash
systemctl status docker
```

By default, the Docker service is inactive. It’s our responsibility to start the service using the following command:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245790620/5cd8b99f-718e-4c74-96ac-1780208ed8b0.png align="center")

```bash
systemctl start docker
```

The Docker service should now be active and running.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748245853460/fb19159e-0825-4f73-a2ea-801b3718af21.png align="center")

Now that docker has been installed. Let us create a custom docker bridge network. By using the docker command:

```bash
docker network create -d bridge mybridge
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748246304667/b28744ec-ede2-439b-a6ab-944e4b39d8a8.png align="center")

```bash
docker network ls
```

This Docker command is used to list all existing networks within the Docker environment.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748246402587/ec26fb29-6fcf-4db7-859e-f5873513fdd8.png align="center")

Now that we’ve created a custom Docker bridge network, we can proceed by pulling a Docker image from Docker Hub. For this project, I will be using the Ubuntu image

```bash
docker pull ubuntu:latest
```

This Docker command pulls the latest Ubuntu image from Docker Hub. If you have a Docker Hub account, log in; if not, feel free to create one.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748246658481/1ebfccf0-1f26-4760-944e-4b5f5e301c5d.png align="center")

In the search bar, type in ubuntu

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748246721878/04254aa6-e8c1-446f-a945-71fdafa2df36.png align="center")

Click on the latest search result, where you’ll see the verification badge confirming that it’s officially verified by Docker

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748246793113/0617aa96-6d7f-4543-b74f-e50574d9fdeb.png align="center")

In the top right corner, you’ll find the `docker pull ubuntu` command. Copy it, then paste it into your terminal to start pulling the Ubuntu image from Docker Hub onto your EC2 instance

```bash
docker pull ubuntu
```

By default, Docker pulls the latest version of an image. Users can also pull specific versions by specifying tags.

```bash
docker pull ubuntu:<version>
```

Replace `<version>` with the desired tag, such as `20.04` or `18.04`.

To check for any existing Docker images in your environment, use the following Docker command:

```bash
docker images
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247063926/bdcb1c65-a163-43c8-b377-e0460ad9ee42.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247103532/3408a262-3c62-4599-b116-fd289fae6af0.png align="center")

Now list out the docker images by using the command mentioned above:

```bash
docker images
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247149049/910c1d5b-6bc3-47cc-8deb-e3336b12c1c0.png align="center")

From this docker image, we can go and create containers by using the command:

```bash
docker run -it --name container1 --network mybridge ubuntu:latest
```

* **docker run** — Starts a new container from an image.
    
* **\-i** — Keeps the container’s input open so you can interact with it.
    
* **\-t** — Allocates a terminal session so you can see and type commands inside the container.
    
* **\--name container1** — Gives the container a friendly name, here it’s `container1`, so it’s easier to manage.
    
* **\--network mybridge** — Connects the container to the custom Docker network named `mybridge`.
    
* **ubuntu:latest** — Specifies the image to use; here it’s the latest version of Ubuntu.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247483134/123cc95c-5203-45a8-ad96-6f515a09ecfe.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247559467/de22e75f-3e90-42de-9440-e1027782bcc3.png align="center")

To list all actively running Docker containers, use the following command:

```bash
docker ps
```

To display all Docker containers regardless of their state, use the following command:

```bash
docker ps -a
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247732943/a0e7f34e-b419-4baf-9fcc-c87f2f670dba.png align="center")

To start any Docker container that has exited, use the following command. In my case, it is:

```bash
docker start container1
```

As you can see above, container1 is running

Let us go ahead and create another container2, using the docker command:

```bash
docker run -it --name container2 --network mybridge ubuntu:latest
```

* **docker run** — Starts a new Docker container from the specified image.
    
* **\-i** — Keeps the container’s standard input open (interactive mode).
    
* **\-t** — Allocates a pseudo-terminal so you can interact with the container’s shell.
    
* **\--name container2** — Assigns the name `container2` to this container for easy reference.
    
* **\--network mybridge** — Connects the container to the custom Docker bridge network named `mybridge`.
    
* **ubuntu:latest** — Specifies the Docker image to use, in this case, the latest Ubuntu image.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247931640/a408ce73-991f-42ac-833a-203090c90290.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748247995479/83706627-de42-487b-9c53-2ada57c9c261.png align="center")

Now that we have created 2 containers within the custom docker bridge network. To verify this action, use the docker command:

```bash
docker network inspect mybridge
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248095973/e2686728-a4d2-48b6-9aaf-f74cd956c377.png align="center")

This Docker command displays detailed information about the `mybridge` network.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248168459/8d84929c-e787-44d3-bcf1-fa2876e82eb7.png align="center")

Now, scroll down to the bottom to view the containers and their detailed information.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248243307/63e67f52-3d20-49e6-af6c-ef8c04cf02df.png align="center")

As shown in the image above, both container1 and container2 are visible along with their key details.

Now, we can perform a ping operation from one container to another. Let’s start by accessing `container1` and pinging `container2`.

```bash
docker exec -it container1 /bin/bash
```

Now, perform the ping operation on `container2`. Copy the IP address of `container2` and use it in this command:

```bash
ping 172.18.0.3
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248478899/93fda3e1-815b-4580-acaa-21f716d9423a.png align="center")

I have successfully accessed Docker container1.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248528556/3c504655-24e5-42ab-97b8-9195d93cc21a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248579118/3db5806d-bfa8-45b9-9055-b949a4a10d8d.png align="center")

By default, the `iputils-ping` package is not installed. Go ahead and install it using the following command:

```bash
apt update && apt install iputils-ping -y
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248829136/cb9fb6eb-a58b-4301-865f-24c07c5cb7a3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248857501/5d86386c-c689-4bb9-88c0-0e1314d7fc2d.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248886863/a522eb01-4267-49eb-b5fe-12853a043c11.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748248902332/5674c22c-8951-4557-a8cd-adf724e6d1c1.png align="center")

After updating and installing the `iputils-ping` package, proceed to perform the ping operation.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748249056472/ca462604-120c-49ba-9186-bbce2237083a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748249083175/ea5c3495-6bea-4ebe-b1cd-c96c1a0c0fdb.png align="center")

We have successfully pinged `container2` from within `container1` using the Docker custom bridge network.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748249179037/e319c83a-d04b-4392-b16f-000933250e67.png align="center")

One of the main advantages of using a custom Docker bridge network is that you can also ping containers by their hostnames. For example:

```bash
ping container2
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1748249298829/5c2b280c-49df-45f2-a72f-984e0ab09b97.png align="center")

This command won't work on the default bridge network—only pinging via IP addresses is allowed there, not hostnames.

Note: Creating a **custom Docker bridge network** allows containers to communicate using **hostnames**, whereas the **default bridge network** only supports communication via **IP addresses**.

This improves clarity, scalability, and ease of container management in multi-container environments.

**Note:** Once inside a Docker container, it's a good practice to update the package lists using `apt update` to ensure access to the latest available packages.

### **Conclusion**

In this mini project, we successfully launched an AWS EC2 instance using Amazon Linux AMI and installed Docker to simulate containerized networking. We created a **custom Docker bridge network** to enable communication between containers, deployed two Ubuntu containers (`container1` and `container2`), and demonstrated successful inter-container communication using both **IP addresses** and **hostnames**—a key advantage over the default bridge network.

This exercise provided hands-on experience with:

* Setting up Docker on a cloud-based Linux instance
    
* Creating and managing Docker containers
    
* Establishing custom network bridges
    
* Executing inter-container communication and troubleshooting missing packages
    

Understanding how custom Docker networks enhance container communication is essential for building scalable and modular containerized applications.

Thank you for reading
