如何在Docker for Windows上访问命名或匿名的Docker卷?

问题描述 投票:1回答:1

如果我运行 docker-compose up 随着 docker-compose.yml 下面,它运行成功,但我无法找到卷在任何地方我的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"

有什么最简单的方法可以自动将docker容器文件如这个postgres数据库转移到Windows 10主机上?

docker docker-compose docker-volume docker-for-windows
1个回答
2
投票

由于docker的内容存在于单独的容器中,而docker有自己的文件系统,所以你需要进入容器内部查看docker容器文件。

为此,你需要在命令提示符下运行以下命令。

docker exec -it <container-id> bash.

我已经尝试了与你的问题中提到的相同的docker-compose.yml,运行docker-compose后,这是我能够查看容器文件内容的方式。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.