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

Share via:

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

Dear Readers,

In this article,we will see Share the Volume In Between Docker Containers.

What is a 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.
1.Share Container to Container.
2.Share Host to Container.

Steps to Follow

Create a Dockerfile and Add Instructions to create container,volume

  1. Connect to Docker Linux EC2 Terminal through Putty.
  2. Switch to root user.
  3. Create a Dockerfile and Add Instruction to create volume.
  4. Create image from above Dockerfile.
  5. Verify images.
  6. Create container “kt-container-1” from image “kt-image-1”.
  7. Verify the volume inside the container.
  8. Create files inside the volume “ktexperts”.

Share volume with another New Container (second container)

  1. Create a New Container and Add to the Volume.
  2. Verify volume
  3. Verify file inside the volume.
  4. Create a new file inside the volume.
  5. Go inside the container-1 and verify files in the volume.

Share volume with another New Container (third container)

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

Create a Dockerfile and Add Instructions to create container,volume

1. Connect to Docker Linux EC2 Terminal through Putty

Open Linux EC2 Instance Terminal

2. Switch to root user

3. Create a Dockerfile and Add Instruction to create volume

Note
:wq! — to quit
4. Create image from above Dockerfile

5. Verify images

6. Create container “kt-container-1” from image “kt-image-1”

7. Verify the volume inside the container

8. Create files inside the volume “ktexperts”

Exit from the container

Share volume with another New Container (second container)
1. Create a New Container and Add to the Volume
We can share volume while creating another container.

To see all the containers

Using below command to create a container and Add to the Volume

2. Verify Volume “ktexperts”

3. Verify file “kt-file1” inside the volume

4. Create a new file inside the volume

Exit from the container

5. Go inside the container-1 and verify files in the volume
We need to start and attach for going inside the container
Go inside the container
To see all the containers

Start Container

Attach Container

Verify files in the volume

Exit from the container

Share volume with another New Container (third container)
1. Create a New Container and Add to the Volume
We can share volume while creating another container.

2. Verify volume

3.Verify files inside the volume

4. Create a new directory inside the volume

Exit from the container

5. Go inside first and second containers “kt-container-1” , “kt-container-2” and verify files/directories inside the volume
Go inside first container “kt-container-1” and verify files/directories inside the volume
To see all the containers

Start Container

Attach Container

Verify files/directories inside the container

Exit from the container

Go inside second container “kt-container-2” 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