Connect Docker to Local Network (original) (raw)

One of the strong features in Docker is robust networking support that allows different containers to communicate with each other and also with external networks seamlessly. The key to using Docker containers in a local network is building distributed applications and microservices architectures; linking them can empower effective communication and resource sharing between them.

Primary Terminologies

Step by Step Process

Method 1: Connecting via Bridge Network

Step 1: Install docker on local machine

Now install docker on local machine by using following command

sudo yum -y install docker

Install docker on local machine

Step 2: Start Docker Daemon

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker

Start Docker Daemon

Step 3: Run a Container with Port Mapping

docker run -d -p 8080:80 --name my_web_server nginx

Run a Container with Port Mapping

Step 4: Accessing the Container from the Local Network

Accessing the Container from the Local Network

Method 2: Using the Host Network

Step 1: Run a Container on the Host Network

docker run -d --network host --name my_server nginx

Run a Container on the Host Network

Step 2: Accessing the Container

Accessing the Container

Method 3: Creating and Using a macvlan Network

Step 1: Create a macvlan Network

docker network create -d macvlan \
--subnet=192.168.1.0/24 \
--gateway=192.168.1.1 \
-o parent=eth0 my_macvlan_net

Create a macvlan Network

Step 2: Run a Container on the macvlan Network

docker run -d --network my_macvlan_net --name server nginx

Run a Container on the macvlan Network

Step 3: Accessing the Container from the Local Network

Accessing the Container from the Local Network: