Concept of Container Linking and Storage in Docker

Last updated on Sep 26 2022
Neha Warghade

Table of Contents

Concept of Container Linking and Storage in Docker

Docker – Container Linking

Container Linking allows multiple containers to link with each other. It is a better option than exposing ports. Let’s go step by step and learn how it works.

Step 1 − Download the Jenkins image, if it is not already present, using the Jenkins pull command.

doc 79

Step 2 − Once the image is available, run the container, but this time, you can specify a name to the container by using the –-name option. This will be our source container.

doc 80

Step 3 − Next, it is time to launch the destination container, but this time, we will link it with our source container. For our destination container, we will use the standard Ubuntu image.

doc 81

When you do a docker ps, you’ll see both the containers running.

Step 4 − Now, attach to the receiving container.

doc 82

Then run the env command. You’ll notice new variables for linking with the source container.

doc 83

doc 84

Docker – Storage

Storage Drivers

Docker has multiple storage drivers that allow one to work with the underlying storage devices. The subsequent table shows the different storage drivers along with the technology employed for the storage drivers.

Technology Storage Driver
OverlayFS overlay or overlay2
AUFS aufs
Btrfs brtfs
Device Manager devicemanager
VFS vfs
ZFS zfs

Let us now discuss some of the instances in which you would use the various storage drivers −

AUFS

  • This is a stable driver; can be employed for production-ready applications.
  • It has good memory usage and is good for ensuring a smooth Docker experience for containers.
  • There is a high-write activity associated with this driver which ought to be considered.
  • It’s good for systems which are of Platform as a service type work.

Devicemapper

  • This is a stable driver; ensures a smooth Docker experience.
  • This driver is good for testing applications within the lab.
  • This driver is in line with the main Linux kernel functionality.

Btrfs

  • This driver is in line with the main Linux kernel functionality.
  • There is a high-write activity associated with this driver which ought to be considered.
  • This driver is good for instances where you maintain multiple build pools.

Ovelay

  • This is a stable driver and it is in line with the main Linux kernel functionality.
  • It has a good memory usage.
  • This driver is good for testing applications within the lab.

ZFS

  • This is a stable driver and it is good for testing applications within the lab.
  • It’s good for systems which are of Platform-as-a-Service type work.

To see the storage driver being employed, issue the docker info command.

Syntax

docker info

Options

None

Return Value

The command will provide all relative information on the Docker component installed on the Docker Host.

Example

sudo docker info

Output

The subsequent output shows that the main driver employed is the aufs driver and that the root directory is stored in /var/lib/docker/aufs.

Data Volumes

In Docker, you have a separate volume that can shared across containers. These are known as data volumes. Some of the features of data volume are −

  • They are initialized when the container is created.
  • They can be shared and also reemployed amongst many containers.
  • Any changes to the volume itself can be made directly.
  • They exist even after the container is deleted.

Let’s look at our Jenkins container. Let’s do a docker inspect to see the details of this image. We can issue the subsequent command to write the output of the docker inspect command to a text file and then view the file accordingly.

sudo docker inspect Jenkins > tmp.txt

When you view the text file using the more command, you’ll see an entry as JENKINS_HOME=/var/Jenkins_home.

This is the mapping that is done withwithin the container via the Jenkins image.

doc 86doc 85

Now suppose you wanted to map the volume within the container to a local volume, then you need to specify the –v option when launching the container. An example is shown below −

sudo docker run –d –v /home/demo:/var/jenkins_home –p 8080:8080 –p 50000:50000 jenkins

The –v option is employed to map the volume within the container which is /var/jenkins_home to a location on our Docker Host which is /home/demo.

doc 87

Now if you go to the /home/demo location on your Docker Host after launching your container, you’ll see all the container files present there.

doc 88

 

Changing the Storage Driver for a Container

If you wanted to change to the storage driver employed for a container, you can do so when launching the container. This can be done by using the –volume-driver parameter when using the docker run command. An example is given below −

sudo docker run –d –volume-driver=flocker    –v /home/demo:/var/jenkins_home –p 8080:8080 –p 50000:50000 jenkins

The –volume-driver option is employed to specify another storage driver for the container.

doc 89

To confirm that the driver has been changed, primary let’s use the docker ps command to see the running containers and get the container ID. So, issue the subsequent command primary −

sudo docker ps

Then issue a docker inspect against the container and put the output in a text file using the command.

sudo docker inspect 9bffb1bfebee > temp.txt

doc 90

If you browse through the text file and go to the line which says VolumeDriver, you’ll see that the driver name has been changed.

doc 91

Creating a Volume

A volume can be created beforehand using the docker command. Let’s learn more about this command.

Syntax

docker volume create –-name=volumename –-opt options

Options

  • name − This is the name of the volume which needs to be created.
  • opt − These are options you can provide while creating the volume.

Return Value

The command will output the name of the volume created.

Example

sudo docker volume create –-name = demo –opt o = size = 100m

Within the above command, we are creating a volume of size 100MB and with a name of demo.

Output

The output of the above command is shown below −

doc 92

Listing all the Volumes

You can also list all the docker volumes on a docker host. More details on this command is given below −

Syntax

docker volume ls

Options

None

Return Value

The command will output all the volumes on the docker host.

Example

sudo docker volume ls

Output

The output of the above command is shown below −

doc 93

So, this brings us to the end of blog. This Tecklearn ‘Concept of Container Linking and Storage 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/devops-training/

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 "Concept of Container Linking and Storage in Docker"

Leave a Message

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