【问题标题】:Add SSL certificate to store in docker添加 SSL 证书以存储在 docker
【发布时间】:2022-09-28 03:19:44
【问题描述】:

我正在尝试创建一个运行 .NET Core API 的简单 docker 映像。问题是,我的环境位于具有自签名证书的代理后面,即不受信任:(

以下是我的码头文件

## runtime:3.1 does not support certoc or openssl or powershell which forced me to change image to nanoserver-1809
#FROM mcr.microsoft.com/dotnet/core/runtime:3.1

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1809 
ARG source
ARG BUILD_ENV=development

# Option - 1 
# ADD z-scaler-certificate.crt /usr/local/share/ca-certificates/z-scaler-certificate.crt
# RUN certoc -addstore root /usr/local/share/ca-certificates/z-scaler-certificate.crt

# Option - 2
# RUN powershell IMPORT-CERTIFICATE -FilePath /usr/z-scaler-certificate.crt -CertStoreLocation \'Cert:\\\\LocalMachine\\Root\'


# Option - 3
# RUN CERT_DIR=(openssl version -d | cut -f2 -d \\\")/certs; cp /usr/z-scaler-certificate.crt $CERT_DIR; update-ca-certificates; fi

# Option - 4
ADD z-scaler-certificate.crt /container/cert/path
RUN update-ca-certificates

WORKDIR /app
COPY ${source:-bin/Debug/netcoreapp3.1} .
ENTRYPOINT [\"dotnet\", \"Webjob.dll\"]

我尝试了几乎所有可以从互联网上尝试的选项,但都失败并出现相同的错误 -

executor failed running [cmd /S /C update-ca-certificates]: unable to find user ContainerUser: invalid argument

我需要帮助来弄清楚我做错了什么,证书没有被添加到商店?

    标签: docker dockerfile docker-for-windows certificate-store


    【解决方案1】:

    为了执行管理任务,您应该使用ContainerAdministrator user

    FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1809 
    ARG source
    ARG BUILD_ENV=development
    USER ContainerAdministrator
    ...
    

    【讨论】:

    • 好吧,我已经这样做了,但它说找不到用户 ContainerAdministrator
    • 尝试在 USER 指令之前启用在容器中运行的检测:ENV DOTNET_RUNNING_IN_CONTAINER=true
    【解决方案2】:

    在使用容器时,除非有充分的理由,否则我建议保持标准的 Linux 技术。这是最标准的选项,适用于 MS Debian 映像:

    COPY z-scaler-certificate.crt /usr/local/share/certificates/z-scaler-certificate.crt
    RUN update-ca-certificates
    

    【讨论】:

      最近更新 更多