简体   繁体   English

使用 docker-compose.yml 中的 Linux 容器在 Windows 主机上挂载 Docker 卷

[英]Mount Docker volume on Windows host with Linux containers in docker-compose.yml

I just started using Docker and the Docker Compose feature to set up my Web App services.我刚刚开始使用 Docker 和 Docker Compose 功能来设置我的 Web 应用程序服务。 I'm running Docker on a Windows Host using Linux Containers.我正在使用 Linux 容器在 Windows 主机上运行 Docker。 I got this named volume called db_volume that I use for my PostgreSQL service.我得到了一个名为 db_volume 的命名卷,用于我的 PostgreSQL 服务。

services:
  postgres_image:
    image: postgres:latest
    ports:
      - "5432"
    restart: always
    volumes:
      - db_volume:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
      POSTGRES_DB: "db1"
volumes:
  db_volume:

When I use docker volume inspect on this named volume, I can see that the Mountpoint path is a Linux path.当我在这个命名卷上使用docker volume inspect时,我可以看到 Mountpoint 路径是一个 Linux 路径。

"Mountpoint": "/var/lib/docker/volumes/dockercompose18019271739475279775_db_volume/_data"

I was wondering if there is any way to convert this path to a Windows one so that I can import these data in my pgadmin databases.我想知道是否有任何方法可以将此路径转换为 ​​Windows 路径,以便我可以将这些数据导入到我的 pgadmin 数据库中。

I already set the COMPOSE_CONVERT_WINDOWS_PATHS=1 in my .env file, but it didn't seem to work.我已经在我的 .env 文件中设置了COMPOSE_CONVERT_WINDOWS_PATHS=1 ,但它似乎不起作用。

I also shared both my C and D drive in the Docker settings.我还在 Docker 设置中共享了我的CD驱动器。

There is no way to convert this to a windows path, because in this scenario it is not on the windows filesystem.无法将其转换为 Windows 路径,因为在这种情况下它不在 Windows 文件系统上。 The storage you have allocated is on the MobyLinux VM which is created as part of your windows install.您分配的存储位于作为 Windows 安装的一部分创建的 MobyLinux VM 上。 If you want to have the storage appear as part of your local windows filesystem then you need to do something like this which maps the data directory to the host filesystem:如果您想让存储作为本地 Windows 文件系统的一部分出现,那么您需要执行以下操作,将数据目录映射到主机文件系统:

version: '3'

services:
  postgres:
    container_name: pg
    image: postgres:latest
    ports:
      - "5432"
    restart: always
    volumes:
      - d:/pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
      POSTGRES_DB: "db1"

You should note that on windows you will need expose your drive via the "Shared Drives" settings in the Docker settings.您应该注意,在 Windows 上,您需要通过 Docker 设置中的“共享驱动器”设置公开您的驱动器。

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

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