Share Volume From Host to Container

Share via:

Share Volume From Host to Container

Dear Readers,

In this article,we will see Share Volume From Host to Container.

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 container “ktexperts-container” and volume by using Command Line

  1. Connect to Docker Linux EC2 Terminal through Putty.
  2. Switch to root user.
  3. Verify files/directories in current directory (/home/ec2-user).
  4. Create a container “ktexperts-container” and volume by using Command Line.
  5. Verify volume.
  6. Verify files inside the volume.
  7. Verify files in host volume (/home/ec2-user).

Share volume with another container (second container)

  1. Create a New Container and Add to the Volume.
  2. Verify volume.
  3. Verify files/directories inside the volume.
  4. Create a directories inside the volume.
  5. Verify files/directories inside host volume (/home/ec2-user).
  6. Go inside the first container “ktexperts-container” and verify files in the volume.

Create a container “ktexperts-container” 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

To see the list of all images

To see the list of all containers

3. Verify files/directories in current directory (/home/ec2-user)

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

4. Verify volume

5. Verify files inside the volume

we can see the files inside the volume which are there in host (/home/ec2-user).

6. Create files inside the volume

Exit from the container

7. Verify files in host volume (/home/ec2-user)

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

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

2. Verify volume

3. Verify files/directories inside the volume

4. Create a directories inside the volume

Exit from the container

5. Verify files/directories inside host volume (/home/ec2-user)

6. Go inside the first container “ktexperts-container” 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  Volume

Verify files/directories inside the volume

Exit from the container

See the list of all details of the containers

To see the full details of the first container “ktexperts-container”

To see the full details of second container “ktexperts-container-1”

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