Share the Volume In Between Docker Containers (Method-2)

Share via:

Share the Volume In Between Docker Containers (Method-2)

Dear Readers,

In this article,we will see Share the Volume In Between Docker Containers (Method-2).

What is Volume?
Volume is a directory inside your container.
First declare directory as a volume then share volume.
Even If we stop container,still we can access the volume.
Volume will be created in one container.
You can declare a directory as volume only while creating container.
We can’t create volume from existing container.
we can share volume across number of containers.
Volume won’t be included when you update an image.
We can map volumes in 2 ways.
Share Container to Container.
Share Host to Container.

Steps to Follow

Create a container “kt-container-4” and volume by using Command Line

  1. Connect to Docker Linux EC2 Terminal through Putty.
  2. Switch to root user.
  3. Create a container “kt-container-4” and volume by using Command Line.
  4. Verify volume.
  5. Create a files inside the volume.

Share volume with another container (fourth container)

  1. Create a New Container and Add to the Volume.
  2. Verify volume.
  3. Verify files inside the volume.
  4. Create a file “ktexperts-file3” inside the volume.
  5. Go inside the fourth container “kt-container-4” and verify files in the volume.

Share volume with another container (fifth container)

  1. Create a New Container and Add to the Volume.
  2. Verify volume.
  3. Verify files inside the volume.
  4. Create a directories inside the volume.
  5. Go inside fourth and fifth containers “kt-container-4”  , “kt-container-5” and verify files/directories inside the volume.

Create a container “kt-container-4” and volume by using Command Line

1. Connect to Docker Linux EC2 Terminal through Putty

Open Linux EC2 Instance Terminal

2. Switch to root user

3. Create a container “kt-container-4” and volume by using Command Line
To see the list of images

To see the list of all containers

Run below command to create a container ” kt-container-4″ with volume “ktexperts-volume” 

4. Verify volume

5. Create a files inside the volume

Exit from the container

Share volume with another container (fourth container)
1. Create a New Container and Add to the Volume
To see the list of containers

Run below command to create a container along with volume

2. Verify volume

3. Verify files inside the volume

4. Create a file “ktexperts-file3” inside the volume

Exit from the container

5. Go inside the fourth container “kt-container-4” and verify files in the volume
We need to start and attach for going inside the container
Go inside the contianer
To see all the containers

Start Container

Attach Container

Verify files inside volume

Exit from the container

Share volume with another container (fifth container)
1. Create a New Container and Add to the Volume

Run below command to create a container along with volume

2. Verify volume

3. Verify files inside the volume

4. Create a directories inside the volume

Exit from the container

5. Go inside fourth and fifth containers “kt-container-4” , “kt-container-5” and verify files/directories inside the volume
Go inside fourth container “kt-container-4” and verify files/directories inside the volume
To see all the containers

Start Container

Attach Container

verify files/directories inside the volume

Exit from the container

Go inside fifth container “kt-container-5” and verify files/directories inside the volume
Start Container

Attach Container

Verify files/directories inside the volume

Exit from the container

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

 

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Add Comment