WSL下的Docker数据卷挂载

说明:通过WSL2装上Ubuntu18.04.在WSL上安装了docker.

正常的docker数据卷挂载:

docker run -it -v  /宿主机绝对路径目录:  /容器内目录  镜像名

在WSL2中,需要把windows体系的目录结构转成wsl下(/mnt):

我们以windows下E盘 data_for_docker_mount文件夹 为例:
在这里插入图片描述

songroom@DESKTOP-MEDPUTU:/$ cd /mnt
songroom@DESKTOP-MEDPUTU:/mnt$ ls
c  d  e  f  g  wsl
songroom@DESKTOP-MEDPUTU:/mnt$ cd e
songroom@DESKTOP-MEDPUTU:/mnt/e$ ls
'$RECYCLE.BIN'                      SouceCsvData_cffex           Temp                    ghos
 0c1f4506f83ee29969ef39665e028dbf   SouceCsvData_digital         TradeData_cffex         h5Data
 MSOCache                           SourceCsvData_future         TradeData_future        qqpcmgr_docpro
 QQMusicCache                       SourceCsvData_stock          Windows10Upgrade        strategy_report
 QQPCMgr                           'System Volume Information'   data_for_docker_mount
songroom@DESKTOP-MEDPUTU:/mnt/e$ cd data_for_docker_mount
songroom@DESKTOP-MEDPUTU:/mnt/e/data_for_docker_mount$ ls
IC1601.csv  IC1604.csv  IC1609.csv  IF1603.csv  IF1606.csv  IH1602.csv  IH1605.csv
IC1602.csv  IC1605.csv  IF1601.csv  IF1604.csv  IF1609.csv  IH1603.csv  IH1606.csv
IC1603.csv  IC1606.csv  IF1602.csv  IF1605.csv  IH1601.csv  IH1604.csv  IH1609.csv
songroom@DESKTOP-MEDPUTU:/mnt/e/data_for_docker_mount$

如果要把此文件夹挂载在特定的docker 容器上(绑定数据卷),应如何操作?

1、绑定数据卷格式


docker run -it -v  /mnt/e/data_for_docker_mount:  /容器内目录  镜像名

2、在启动时绑定

docker run -it -v /mnt/e/data_for_docker_mount:/docker_local_data python:3
.8

3、在容器中操作,看是否进来了

>>> path="/docker_local_data"
>>> import os
>>> os.listdir(path)
['IC1601.csv', 'IC1602.csv', 'IC1603.csv', 'IC1604.csv', 'IC1605.csv', 'IC1606.csv', 'IC1609.csv', 'IF1601.csv', 'IF1602.csv', 'IF1603.csv', 'IF1604.csv', 'IF1605.csv', 'IF1606.csv', 'IF1609.csv', 'IH1601.csv', 'IH1602.csv', 'IH1603.csv', 'IH1604.csv', 'IH1605.csv', 'IH1606.csv', 'IH1609.csv']
>>>

问题:

1、上面是新开容器

如果这个容器已经开了,不是新开,如何与宿主机的目录进行挂载?

2、容器如何与宿主机的多个目录进行挂载?

方案:多写几对v;上面只写了一对-v.

3、容器与容器之间。

方案:–volumes-from

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页