Problems with volumes in docker-compose

  docker, question

图片描述

Mysite.template is a file, but mapping to docker becomes a directory. May I know where it was written wrong?

Reason

The first thing to know is that the Docker engine can only be run on Linux kernel systems, and the Docker engine cannot be directly run on Windows and macOS systems. The initial solution is to create a virtual machine locally, which is the function provided by Docker Machine. Create a virtual machine for a Linux system with Docker already installed. Later, Docker Company introduced the Docker for Windows and Docker for Mac that we currently use in order to make Docker have a good localization experience on computers that we normally work on.

DFW and DFM both use their own virtual technologies. For example, if you use DFW, you need to open Hype-V on Windows. In terms of user experience, it makes us feel that Docker is running locally, but in fact, it still uses some virtual technologies. This leads to the problem of poor performance of the shared data volume, that is, if you have a lot of website files (such as Drupal), you set up a shared data volume locally and share the website files to containers, you will find that the website will run at a rather slow speed. It may be several tens of times worse than the actual performance.

When developing websites locally, we should set up shared data volumes and share website files to containers. In the production environment, the files of the website should have been Build into the mirror image, so there will be no performance problem. Even if shared data volumes are used in a production environment, performance issues will not be encountered. Therefore, we need to find a way to solve the performance problem of this data volume only when developing locally.

Solve

The solution I found is to use a name calleddocker-syncThe main function of the tool is to let us create a container for synchronizing files. It will use our own synchronization method to synchronize local files into this container. This synchronization can also be bi-directional, i.e. changes to files in the container will also be synchronized locally. Other services required by the website can use the data volume created by this synchronization container, which goes beyond the method of sharing data volume used by DFW or DFM, thus solving the performance problem of data volume.

To be honest, this is really a little complicated. Docker itself is a bit confusing. We are still struggling with the difference between containers and virtual machines because we have brought some new concepts to solve the performance problem of local container data volumes. For example, docker-sync is a set of tools. You have to install it first. It is written in Ruby language and can be installed by gem command. Docker-sync provides some methods for synchronizing files, among which I use the unison method, which is a tool for two-way synchronization.

Unison is an independent tool that docker-sync uses to synchronize files between the host and the container. This synchronization is only used in our local development, because to solve the performance problem, you do not need to use synchronization in the production environment. Even if your website is running on a shared data volume, there will be no performance problems. Be sure to keep this in mind. Synchronizing files is only to solve the performance problems of shared data volumes encountered during local development.