mount same volume

Suppose, I have an apache container running and I need to create more apache containers using the same data volumes. The mounted drive name is dockerdata. We can use the same volume and mount it in a docker container. Let’s see, how to mount the same volume in a docker container.

Check Out: How To Configure GZip Compression In Apache Server Linux

How To Mount Same Volume To Multiple In Docker:

First Apache Container:

docker run -itd --name apachecon -p 80:80 -v /root/dockerdata:/var/www/html/ 470671670cac /bin/bash
docker ps

docker volume mount

You can access the apache container using the below command and if you want to exit the container press ctrl+p+q otherwise the container would be stopped if you directly exist using exit command.

docker attach apachecon

Check Out: Learn Useful Tar Command With Example In Linux

Once you’re inside the container, you can start apache service using /sbin/httpd -D start

mount same volume docker

Now it’s time to test the apache website hosting.

cd /var/www/html/
echo " testing website " > index.html

you can find the IP address using ip a or ipconfig command and then run curl 172.17.0.2.

docker use same volume

Check Out: Deploy Container Using Docker Swarm Cluster On Linux

Check the index.html file exist on your mount point and I’m also able to access the website outside the container.

volume use in container

Everything is working perfectly and I will create a new apache container using the same mount volume.

 docker run -itd --name apachecon1 -p 81:80 -v /root/dockerdata:/var/www/html/ 470671670cac /bin/bash

Create a directory inside /var/www/html using mkdir test.

I’m able to store data in the same mounted directory for all the running containers.

Check Out: How To Extend LVM For Volume Group Size On Linux

As you see both containers are running.

You’re done docker volume mount volume use in container

LEAVE A REPLY

Please enter your comment!
Please enter your name here