docker-compose mount directory

Docker Compose can use volumeskeywords to mount directories and map host directories or files to containers.

grammar:

volumes:
  - <host directory>:<container directory>

Among them, <宿主机目录>the host directory path to be mapped can be a relative path or an absolute path; the <容器目录>target path mounted in the container can also be a relative path or an absolute path.

Example:

Mount the host's current directory to the container's /appdirectory:

version: "3"
services:
  web:
    image: nginx
    volumes:
      - .:/app

In the above example, webthe service uses the Nginx image, and maps the current directory (that is, the directory where docker-compose.yml is located) to the /appdirectory in the container. At this point, /appthe directory can read and write files in the current directory of the host.

Note that in the Windows system, due to the different file systems, absolute paths need to be used for mounting. For example:

version: "3"
services:
  web:
    image: nginx
    volumes:
      - C:\Users\myuser\project:/app

The above example maps a local C:\Users\myuser\projectdirectory into the container's /appdirectory.

Guess you like

Origin blog.csdn.net/SMILY12138/article/details/130305102