gpt4 book ai didi

docker - 如何在Windows版Docker上访问命名或匿名Docker卷?

转载 作者:行者123 更新时间:2023-12-02 18:59:58 26 4
gpt4 key购买 nike

如果我使用下面的docker-compose up运行docker-compose.yml,则它可以成功运行,但是无法在Windows 10文件中的任何位置找到该卷。我 checkin 了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保留其自己的文件系统,因此您需要进入容器内部以查看docker容器文件。

为此,您需要从命令提示符处运行以下命令:
docker exec -it <container-id> bash

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

enter image description here

关于docker - 如何在Windows版Docker上访问命名或匿名Docker卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61468497/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com