Steps To Create And Attach Bind Mount To The Docker Container
Follow the steps Mentioned below to create and attach the bind mount to docker container.
Step 1: First create an empty directroy in the docker host which you want to attach the application that you are dockerizing the application.
Mkdir <Name Of the Volume You wan to Create>
Step 2: Know this directory will act as an volume on the docker host you need to mount this to the path where the data will br stored in the application as show in the image below you can use the following command to do this.
sudo docker run -d <Container ID> --name <Name Of the Container> -v <Host Path>:<Container Path>
/home/ubuntu/nginx is the host path where my directory of volume is located and the /app is the contaienr path.
How To Use Bind Mount In Docker?
Bind mounts and the host filesystem are tightly related. The host filesystem is immediately impacted by changes made to a bind mount, and vice versa. When you use a bind mount to remove a container, the related data stays on the host.