In a nutshell
Suppose you had the following bind mount in a
What does the
./:/var/www/html entry actually mean?
Assuming your current directory (where the
docker-compose.yml file is located) is
/Users/sajad/sites/wordpress/sajadtorkamani, you’re telling Docker to “bind” the
/Users/sajad/sites/wordpress/sajadtorkamani on your host/local machine to the
/var/www/html directory inside the
Now, any changes made to the files inside the
/Users/sajad/sites/wordpress/sajadtorkamani directory on the host machine is immediately reflected on the container file system at
/var/www/html, and vice-versa.
So if you were to add a new file with
touch hello.txt at
hello.txt file would also get created at
This ensures that the host filesystem at
/Users/sajad/sites/wordpress/sajadtorkamani and container filesystem at
/var/www/html for are always in sync.
Example use cases
If you make changes to the source code in your host filesystem, you want it to sync with the container filesystem automatically without needing to rebuild the container.
If you’re using an Nginx container, you want your changes at a
docker/nginx.conf file to be synced with a
/usr/local/etc/nginc.conf file inside the Nginx container.
You want changes made by a MySQL container at
/var/lib/mysql to be bound to an external named volume so that the data is persisted even if the MySQL container is stopped.