
Sudo docker run -it -v tutorialspoint:/sharedVol -name container03 ubuntu sudo docker rm -f container01 container02 Let’s try it using the following commands. Now, if you delete both the containers and create a new container and mount the tutorialspoint volume, you will find the file created there. Inside the bash of this container, go to the sharedVol directory and you will find the file which you created in container01. sudo docker run -it -v tutorialspoint:/sharedVol -name container02 ubuntu container02) and mount the same volume there also. Check that the file has been created using the ls command. Move to that directory and create a file (dockertutorials.txt) with a message “Welcome to docker tutorialspoint”. You will also find the sharedVol directory there. The ls command will list all the directories inside the container. lsĮcho “Welcome to docker tutorialspoint” > dockertutorials.txt Inside the bash, type the following commands one by one. Now, we will try to create a new file inside the /sharedVol directory through the container’s bash. In the above command, -i flag is used to display the bash in an interactive shell, -v flag is used to mount the tutorialspoint volume that you just created to a new directory called sharedVol which is created inside the container01. sudo docker run -it -v tutorialspoint:/sharedVol -name container01 ubuntu container01) using base image ubuntu and mount the tutorialspoint volume to that container and access that container using the bash. sudo docker volume inspect tutorialspoint

You can also inspect the volume that you just created using the following command. tutorialspoint) using the following command. Now, create a new volume with any name (Eg. To display all the existing volumes, use the following command. We will also try deleting the containers and then access the same file through another container. We will then create a file inside the volume and will access the same file through both the containers. In this article, we will create a volume and mount it to two different containers. By doing so, all the containers will have shared access to the particular volume and you will be able to access and modify files in that volume. You can do so, be creating a volume and mounting it to all the containers.

Now, you want to create a shared directory between all the containers such that from all the containers you can access that directory or volume and perform changes in the files in that directory from any container. In some projects, there might be scenarios where you have created multiple containers for different parts of the project and some of those containers share common files as well.
