Docker中的postgres与命名或绑定卷上的数据目录在Windows Server 2019上运行,但不适用于Windows Server 2016

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

我目前正在尝试在Docker容器中运行PostgreSQL 10.6.1(Base-Image是mcr.microsoft.com/windows/servercore:ltsc2016),应该在Windows Server 2016 Datacenter(版本1607,Build 14393.2759)上运行。

一切运行良好,包括PostgreSQL的initdb和之后运行的PostgreSQL - 只要PostgreSQL的数据目录不是docker主机上的卷。

如果我尝试运行它将PostgreSQL的数据目录放在named or bind volume上,PostgreSQL能够执行其initdb但后来无法启动。

我怀疑这个错误是由于装载的卷在容器中可见为symlink,这取决于mcr.microsoft.com/windows/servercore:ltsc2016,导致PostgreSQL失败。在mcr.microsoft.com/windows/servercore:1809上,这种行为发生了变化 - 挂载的卷看起来像'普通'目录,PostgreSQL能够启动。

由于根本没有有用的错误消息,并且在容器外运行没有持久存储的数据库听起来像一个真正无用的东西,所以任何帮助都是值得赞赏的。

我正在使用的Dockerfile如下所示:

FROM mcr.microsoft.com/windows/servercore:ltsc2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG version=10.6-1

RUN [Net.ServicePointManager]::SecurityProtocol = 'Tls12, Tls11, Tls' ; \
    Invoke-WebRequest $('https://get.enterprisedb.com/postgresql/postgresql-{0}-windows-x64-binaries.zip' -f $env:version) -OutFile 'postgres.zip' -UseBasicParsing ; \
    Expand-Archive postgres.zip -DestinationPath C:\ ; \
    Remove-Item postgres.zip ; \
    Remove-Item 'C:\pgsql\pgAdmin 4' -Recurse ; \
    Remove-Item 'C:\pgsql\StackBuilder' -Recurse ; \
    Remove-Item 'C:\pgsql\doc' -Recurse
RUN [Net.ServicePointManager]::SecurityProtocol = 'Tls12, Tls11, Tls' ; \
    Invoke-WebRequest 'http://download.microsoft.com/download/0/5/6/056DCDA9-D667-4E27-8001-8A0C6971D6B1/vcredist_x64.exe' -OutFile vcredist_x64.exe ; \
    Start-Process vcredist_x64.exe -ArgumentList '/install', '/passive', '/norestart' -NoNewWindow -Wait ; \
    Remove-Item vcredist_x64.exe

SHELL ["cmd", "/S", "/C"]
RUN setx /M PATH "C:\pgsql\bin;%PATH%"
RUN MD data
RUN setx /M PGDATA "C:\data"

ENV PGUSER postgres
ENV PGPASSWORD postgres

COPY docker-entrypoint.cmd /
COPY start.cmd /

EXPOSE 5432

ENTRYPOINT ["docker-entrypoint.cmd"]
CMD [ "start.cmd"]

引用的docker-entrypoint.cmd看起来像这样:

@ECHO %PGPASSWORD% > pw.txt

@ECHO OFF
IF NOT EXIST %PGDATA%/PG_VERSION (
    initdb.exe --encoding=UTF8 --username=%PGUSER% --pwfile=pw.txt
    @echo host all all 0.0.0.0/0 trust > %PGDATA%/pg_hba.conf
    @echo host all all ::0/0 trust >> %PGDATA%/pg_hba.conf
)

%*

引用的start.cmd看起来像这样:

@echo off

pg_ctl start -o "-h * -c max_prepared_transactions=100 -c max_connections=1000"

REM logic to keep container alive
:ENDLESS
CALL :sleep 100000
goto ENDLESS
exit

REM https://superuser.com/questions/48231/how-do-i-make-a-batch-file-wait-sleep-for-some-seconds
:sleep
ping 127.0.0.1 -n %1 -w 1000 > NUL
postgresql docker windows-server-2016 windows-container
1个回答
0
投票

类似的问题已经报道[moby / moby#25908](https://github.com/moby/moby/issues/25908),但是被重定向到这里以便在https://github.com/docker/for-win/issues上检查/打开我在打开和关闭问题列表中搜索了这个问题,但找不到任何问题。

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