简体   繁体   English

Postgres Docker容器数据无法挂载到本地

[英]Postgres Docker Container data fails to mount to local

I'm trying to do data persistence in postgres. 我正在尝试在postgres中进行数据持久化。 But when I want to mount the data folder into my local file, I get this error. 但是,当我要将数据文件夹安装到本地文件中时,会出现此错误。

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
LOG:  could not link file "pg_xlog/xlogtemp.25" to "pg_xlog/000000010000000000000001": Operation not permitted
FATAL:  could not open file "pg_xlog/000000010000000000000001": No such file or directory
child process exited with exit code 1
initdb: removing contents of data directory "/var/lib/postgresql/data"
running bootstrap script ...

Here's my YAML file 这是我的YAML文件

version: '3.1'

services:

  postgres:
    restart: always
    image: postgres:9.6.4-alpine
    ports:
      - 8100:5432
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    environment:
      POSTGRES_PASSWORD: root

I'm using docker toolbox on windows. 我在Windows上使用docker工具箱。 The docker machine in Virtual Box. Virtual Box中的docker机器。

Looks like it has to be /mnt/sda1/var/lib/docker/volumes/psql/_data for windows docker toolbox. 看起来对于Windows docker工具箱它必须是/ mnt / sda1 / var / lib / docker / volumes / psql / _data。 This worked for me 这对我有用

docker run -it --name psql -p 5432:5432 -v psql:/var/lib/postgresql/data postgres:9.5-alpine

"Mounts": [
            {
                "Type": "volume",
                "Name": "psql",
                "Source": "/mnt/sda1/var/lib/docker/volumes/psql/_data",
                "Destination": "/var/lib/postgresql/data",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }

docker volume ls 码头工人卷ls

DRIVER              VOLUME NAME
local               65f253d220ad390337daaacf39e4d17000c36616acfe1707e41e92ab26a6a23a
local               761f7eceaed5525b70d75208a1708437e0ddfa3de3e39a6a3c069b0011688a07
local               8a42268e965e6360b230d16477ae78035478f75dc7cb3e789f99b15a066d6812
local               a37e0cf69201665b14813218c6d0441797b50001b70ee51b77cdd7e5ef373d6a
local               psql

Please refer this for more info: bad mount 请参考此以获得更多信息: 错误的安装

It looks like you use a shared data directory (host dir shared into the virtual) for database storage. 好像您使用共享数据目录(主机目录共享到虚拟目录中)进行数据库存储。

Only two options make sense: 只有两个选择才有意义:

1) you have a trivial issue with directory permissions 1)目录权限有一个小问题

2) you hit a known problem (google!) with some VirtualBox and also VmWare versions that on some Windows versions, you cannot create symlinks in directories shared from the host to virtual machine. 2)您使用某些VirtualBox以及VmWare版本遇到了一个已知问题(google!),在某些 Windows版本上,您无法在从主机到虚拟机的共享目录中创建符号链接。

for (2), a workaround is to NOT use shared folder to keep data. 对于(2),一种解决方法是不使用共享文件夹保留数据。

Either way, it's a problem which should be solved by the provider of the docker image itself, or by the provider of virtualizer (vbox, vmware etc). 无论哪种方式,这都是应该由docker映像本身的提供程序或由虚拟化程序(vbox,vmware等)提供程序解决的问题。

This is NOT a fault of Windows OS, or PostgreSQL. 这不是Windows OS或PostgreSQL的故障。

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

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