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 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.

What does mounting mean?

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.

Why do I need to mount folders?

Folder mounting in Docker Compose allows you to exchange data between the host machine and containers, which provides several benefits and opportunities:

  1. Data persistence: using folder mounting, you can persist data created or modified inside containers to the host machine. This is important for preserving persistent data, such as databases or file systems, which can be restored after the containers are restarted.
  2. Code updates: if you are developing an application and want to instantly see code changes without having to rebuild the image and restart the container, mounting folders is a great way to do this. You can mount the source code folder on the host machine inside the container, and when code files change on the host, they are automatically displayed inside the container without having to restart it.
  3. Splitting configurations: you can also use folder mounting to split 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 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: