Bootstrap

docker挂载卷的几种方式

一、通过卷安装

使用CLI或docker desktop 创建卷并启动容器
创建卷:

docker volume create todo-db

将创建的卷挂载到容器中:

docker run -dp 127.0.0.1:3000:3000 --mount type=volume,src=todo-db,target=/etc/todos getting-started

查看主机中卷数据的存储路径:

docker volume inspect todo-db
[
    {
        "CreatedAt": "2019-09-26T02:18:36Z",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/todo-db/_data",
        "Name": "todo-db",
        "Options": {},
        "Scope": "local"
    }
]

二、通过绑定安装

docker run -it --mount type=bind,src="$(pwd)",target=/src ubuntu bash

容器中的src路径挂载到pwd路径,该方式可以指定主机的挂载路径,便于管理和维护

三、在compose.yaml指定挂载点

services:
  app:
    # The app service definition
  mysql:
    image: mysql:8.0
    volumes:
      - todo-db:/var/lib/mysql

volumes:
  todo-db:$(pwd)
;