Methods of payment Abuse

Mounting folders in Docker

12.09.2023, 23:41
Mounting folders (or file systems) means linking or connecting a file system (folder or directory) to a specific location in another file system. This allows you to make the contents of one folder available inside another folder or even elsewhere in the system.

What does mounting mean?

Folder mounting is an important function of operating systems and is often used in the context of containerization, such as Docker or virtualization, to provide access to files and data between the host machine and containers or virtual machines.
The basic idea of mounting folders is to divide the physical storage area (for example, disk or file system) into different logical areas for organizing and accessing files. This allows you to control and change the contents of the 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 configure configuration files.
 

Why do I need to mount folders?

Mounting folders in Docker Compose allows you to exchange data between the host machine and containers, which provides several advantages and opportunities:
  1. Data Saving: Using folder mounting, you can save data created or modified inside containers on the host machine. This is important to preserve persistent data, such as databases or file systems, which can be restored after restarting containers.
  2. Code Update: If you are developing an application and want to see code changes instantly without having to rebuild the image and restart the container, mounting folders is a great way. You can mount the source code folder on the host machine inside the container, and when you change the code files on the host, they are automatically displayed inside the container without having to restart it.
  3. Configuration Separation: You can also use folder mounting to separate configuration files between the host machine and containers.

How to mount?

In Docker Compose, you can mount host machine folders into containers using the `volumes` option. Here is an example of R using volumes in a docker-compose file.yml:
 
yaml

version: '3'

services:

app:

image: nginx

volumes:
- /path/to/folder/host:/path/to/folder/container
In the example above, `/path/to/folder/host` is the path to the folder on your host machine that you want to mount in the container. `/path/to/folder/container` 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 ones by 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:

- ./folder/host:/path/to/folder/container
You can also specify multiple mounted folders by simply adding them to the `volumes` list.
yaml

version: '3'

services:

app:

image: nginx

volumes: