【问题标题】:How to access named or anonymous Docker volumes on Docker for Windows?如何访问 Docker for Windows 上的命名或匿名 Docker 卷?
【发布时间】:2020-04-27 21:08:09
【问题描述】:

如果我使用下面的docker-compose.yml 运行docker-compose up,它会成功运行,但我无法在 Windows 10 文件中的任何位置找到该卷。我签入了C:\Users\Public\Documents\Hyper-V\Virtual hard disks,但它是空的。

version: "3"
services:
  database:
    image: postgres:12.2
    volumes:
      - /var/lib/postgresql/data
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

如果我尝试使用如下所示的 Windows 路径指定卷的主机位置,则会收到有关权限的错误

version: "3"
services:
  database:
    image: postgres:12.2
    volumes:
      - c:/docker-volumes/database:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres  

database_1  | The files belonging to this database system will be owned by user "postgres".
database_1  | This user must also own the server process.
database_1  |
database_1  | The database cluster will be initialized with locale "en_US.utf8".    
database_1  | The default database encoding has accordingly been set to "UTF8".     
database_1  | The default text search configuration will be set to "english".       
database_1  |
database_1  | Data page checksums are disabled.
database_1  |
database_1  | fixing permissions on existing directory /var/lib/postgresql/data ... 
ok
database_1  | creating subdirectories ... ok
database_1  | selecting dynamic shared memory implementation ... posix
database_1  | selecting default max_connections ... 20
database_1  | selecting default shared_buffers ... 400kB
database_1  | selecting default time zone ... Etc/UTC
database_1  | creating configuration files ... ok
database_1  | running bootstrap script ... 2020-04-27 21:00:29.194 UTC [81] FATAL:  
data directory "/var/lib/postgresql/data" has wrong ownership
database_1  | 2020-04-27 21:00:29.194 UTC [81] HINT:  The server must be started by 
the user that owns the data directory.
database_1  | child process exited with exit code 1
database_1  | initdb: removing contents of data directory "/var/lib/postgresql/data"

将像这个 postgres 数据库这样的 docker 容器文件自动传输到 Windows 10 主机的最简单方法是什么?

【问题讨论】:

    标签: docker docker-compose docker-volume docker-for-windows


    【解决方案1】:

    由于 docker 内容存在于单独的容器中,并且 docker 拥有自己的文件系统,因此您需要进入容器内部才能查看 docker 容器文件。

    为此,您需要从命令提示符运行以下命令:

    docker exec -it <container-id> bash.

    我已尝试使用您的问题中提到的相同 docker-compose.yml,并且在运行 docker-compose up 后,这是我能够查看容器文件内容的方式:

    【讨论】:

    • 这对于查看容器的文件系统很有用,但不使用卷,也不会将文件放入 Windows。我希望能够使用卷访问 Windows 主机上的数据。那可能吗?我找不到任何文档或 GitHub 问题说这是不可能的,但也找不到任何关于如何做到这一点的明确答案
    猜你喜欢
    • 2019-08-23
    • 2017-12-12
    • 2020-02-07
    • 2020-07-10
    • 1970-01-01
    • 2019-07-30
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多