Mounting folders (or file systems) means linking or connecting a file system (folder or directory) to a specific location on another file system. This allows you to make the contents of one folder accessible within another folder or even at another location on the system.
Folder mounting is an important feature of operating systems and is often used in the context of containerization such as Docker or virtualization to allow access to files and data between the host machine and containers or virtual machines.
The basic idea behind folder mounting is to divide an area of physical storage (such as a disk or file system) into different logical areas to organize and access files. This allows you to control and modify the contents of a file system without affecting other file systems or directories.
Folder mounting is often used to exchange data between the host machine and containers, update code during application development, store databases, or customize configuration files.
Folder mounting in Docker Compose allows you to exchange data between the host machine and containers, which provides several benefits and opportunities:
In Docker Compose, you can mount host machine folders into containers using the `volumes`
option. Here is an example of using volumes
in the docker-compose.yml
file:
yaml
version: '3'
services:
app:
image: nginx
volumes:
- /path_to_host_folder:/path_to_folder_volume
In the above example,"/path_to_host_folder
" is the path to the folder on your host machine that you want to mount in a container. `/path_to_folder_volume`
is the path to the folder inside the container where you want to mount the host folder.
You can also use relative paths instead of absolute paths, specifying the path relative to the location of the `docker-compose.yml`
file. In this case, use `./`
to specify the current directory.
yaml
version: '3'
services:
app:
image: nginx
volumes:
- ./host's_folder:/path_to_folder_volume
You can also specify multiple mounted folders by simply adding them to the `volumes`
list.
yaml
version: '3'
services:
app:
image: nginx
volumes: