代码之家  ›  专栏  ›  技术社区  ›  sven

Windows Server 2016上Windows容器中的PostgreSQL出现问题

  •  1
  • sven  · 技术社区  · 6 年前

    我正在试着跑 PostgreSQL 10.6.1 在docker容器中(基本图像是 mcr.microsoft.com/windows/servercore:ltsc2016 )它应该在WindowsServer2016数据中心(1607版本,内部版本14393.2759)上运行。

    initdb 然后运行PostgreSQL——只要PostgreSQL的数据目录不是docker主机上的卷。

    如果我试图运行它,将PostgreSQL的数据目录放在 named or bind volume ,PostgreSQL能够 初始数据库 但后来没能开始。

    我怀疑错误是由于装入的卷在 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
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   Sobin Benny    6 年前

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