Networking in Docker

Last updated on May 27 2022
Raigiri Patil

Table of Contents

Networking in Docker

Docker – Networking

Docker takes care of the networking aspects so that the containers can communicate with other containers and also with the Docker Host. If you do an ifconfig on the Docker Host, you’ll see the Docker Ethernet adapter. This adapter is created when Docker is installed on the Docker Host.

Page 1 Image 1 66
ifconfig

This is a bridge between the Docker Host and the Linux Host. Now let’s look at some commands associated with networking in Docker.

Listing All Docker Networks

This command can be used to list all the networks associated with Docker on the host.

Syntax

docker network ls

Options

None

Return Value

The command will output all the networks on the Docker Host.

Example

sudo docker network ls

Output

The output of the above command is shown below

Page 2 Image 2 58
dock network

Inspecting a Docker network

If you want to see more details on the network associated with Docker, you can use the Docker network inspect command.

Syntax

docker network inspect networkname

Options

  • networkname − This is the name of the network you need to inspect.

Return Value

The command will output all the details about the network.

Example

sudo docker network inspect bridge

Output

The output of the above command is shown below −

Page 3 Image 3 26
inspect bridge

Now let’s run a container and see what happens when we inspect the network again. Let’s spin up an Ubuntu container with the subsequent command −

sudo docker run –it ubuntu:latest /bin/bash

Page 3 Image 4 33
docker run

Now if we inspect our network name via the subsequent command, you’ll now see that the container is attached to the bridge.

sudo docker network inspect bridge

Page 4 Image 5 22
attached container

Creating Your Own New Network

One can create a network in Docker before launching containers. This can be done with the subsequent command −

Syntax

docker network create –-driver drivername name

Options

  • drivername − This is the name used for the network driver.
  • name − This is the name given to the network.

Return Value

The command will output the long ID for the new network.

Example

sudo docker network create –-driver bridge new_nw

Output

The output of the above command is shown below −

Page 5 Image 6 17
driver bridge

You can now attach the new network when launching the container. So let’s spin up an Ubuntu container with the subsequent command −

sudo docker run –it –network=new_nw ubuntu:latest /bin/bash

Page 5 Image 7 13
launching container

And now when you inspect the network via the subsequent command, you’ll see the container attached to the network.

sudo docker network inspect new_nw

Page 5 Image 8 15
network inspect new

 

So, this brings us to the end of blog. This Tecklearn ‘Networking in Docker’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive, Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/containerization-using-docker/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

 

0 responses on "Networking in Docker"

Leave a Message

Your email address will not be published. Required fields are marked *