简体   繁体   English

从Windows 10的WSL将体积设置为Docker容器

[英]Set volume to docker container from wsl from windows 10

In my windows i installed docker and ubuntu 18.4 wsl.So after expose daemon on localhost, i can use windows daemon on ubuntu wsl. 在我的Windows中,我安装了docker和ubuntu 18.4 wsl。因此在本地主机上公开守护程序后,我可以在ubuntu wsl上使用Windows守护程序。

I created a directory's on drive d and i made a file into data directory like below: 我在驱动器d上创建了目录,并将文件制作到数据目录中,如下所示:

PS D:\wsl\data> dir
    Directory: D:\wsl\data
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        8/31/2019   2:27 PM              0 New Text Document.txt
PS D:\wsl\data>

after that, i run a postgres container like below on wsl teminal: 之后,我在wsl teminal上运行如下所示的postgres容器:

$ docker run  --name=pg-docker3  -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123  -v /mnt/d/wsl/data:/var/lib/postgresql/data mdillon/postgis:11-alpine

After creating container i open container by bash : 创建容器后,我通过bash打开容器:

$ docker exec -it pg-docker3 bash

This is data postgres directory: 这是数据postgres目录:

bash-4.4# ls /var/lib/postgresql/data
PG_VERSION            pg_commit_ts          pg_logical            pg_serial             pg_subtrans           pg_xact               postmaster.pid
base                  pg_dynshmem           pg_multixact          pg_snapshots          pg_tblspc             postgresql.auto.conf
data                  pg_hba.conf           pg_notify             pg_stat               pg_twophase           postgresql.conf
global                pg_ident.conf         pg_replslot           pg_stat_tmp           pg_wal                postmaster.opts
bash-4.4# 

as you can see data directory construct in location but when i listed thing's inside data directory i can see my text file that created in host machine !!! 如您所见, data目录结构位于位置,但是当我列出数据目录中的内容时,我可以看到在主机中创建的文本文件!

I created a directory inside data directory calld kk . 我在数据目录kk创建了一个目录。

bash-4.4# ls /var/lib/postgresql/data
PG_VERSION            pg_commit_ts          pg_logical            pg_serial             pg_subtrans           pg_xact               postmaster.pid
base                  pg_dynshmem           pg_multixact          pg_snapshots          pg_tblspc             postgresql.auto.conf
data                  pg_hba.conf           pg_notify             pg_stat               pg_twophase           postgresql.conf
global                pg_ident.conf         pg_replslot           pg_stat_tmp           pg_wal                postmaster.opts
bash-4.4# ls /var/lib/postgresql/data/data/
kk
bash-4.4#

But not create this directory inside host as you can see: 但是您不能看到在主机内部创建此目录:

PS D:\wsl\data> dir

    Directory: D:\wsl\data

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        8/31/2019   2:27 PM              0 New Text Document.txt

Where is the /var/lib/postgresql/data/data/ ? /var/lib/postgresql/data/data/哪里? and why it not appeared in /mnt/d/wsl/data ? 以及为什么它不出现在/ mnt / d / wsl / data中?

You must move your mounting path from /mnt to /. 您必须将安装路径从/ mnt移至/。 In this answer there is the following explanation : Can you run Docker natively on the new Windows 10 (Ubuntu) bash userspace? 在此答案中,存在以下解释: 您可以在新的Windows 10(Ubuntu)bash用户空间上本地运行Docker吗?

Volumes 卷数

Take care when adding volumes. 添加卷时请多加注意。 The path C:\\dir will be visible as /mnt/c/dir on WSL and as /c/dir/ by docker engine. 路径C:\\dir在WSL上将显示为/mnt/c/dir ,而在docker引擎中将显示为/c/dir/ You can overcome it permanently: 您可以永久克服它:

sudo bash -c "echo -e '[automount] \nroot = /'>/etc/wsl.conf"

You must exit and reload WSL after making the change to wsl.conf so that WSL reads in your changes on launch. 对wsl.conf进行更改后,必须退出并重新加载WSL,以便WSL在启动时读取更改。

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM