USE HTTPS by Running the Container with a Certificate

This article was translated from English: Does it need improvement?
Translated
View the article in English

If you need to run the container with a certificate, follow these steps to generate the certificate and configure the local machine:

Run the IronSecureDoc Container With a Certificate

  1. Generate Certificate:

    # Generates a new HTTPS certificate for use with ASP.NET Core.
    # Saves the certificate at the specified path and protects it with a password.
    dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>
    
    # Trusts the generated certificate on your local machine.
    dotnet dev-certs https --trust
    # Generates a new HTTPS certificate for use with ASP.NET Core.
    # Saves the certificate at the specified path and protects it with a password.
    dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>
    
    # Trusts the generated certificate on your local machine.
    dotnet dev-certs https --trust
    SHELL

    Replace <CREDENTIAL_PLACEHOLDER> with a password.

  2. Run the Docker Container:

    # Runs the IronSecureDoc Docker container with both HTTP and HTTPS ports exposed.
    docker container run -d \
     -p 8081:8081 -p 8080:8080 \ # Maps container ports to host ports for HTTP and HTTPS.
     -e HTTP_PORTS=8080 \ # Sets the HTTP port for the application.
     -e HTTPS_PORTS=8081 \ # Sets the HTTPS port for the application.
     -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \ # Provides the IronSecureDoc license key.
     -e ENVIRONMENT=Production \ # Configures the environment as Production.
     -v %USERPROFILE%\.aspnet\https:/https:ro \ # Mounts the directory to the container as read-only.
     -e CERTIFICATE_PATH=%USERPROFILE%\.aspnet\https\ironsecuredoc.pfx \ # Specifies the path to the certificate in the container.
     -e CERTIFICATE_PASSWORD=<CERTIFICATE_PASSWORD> \ # Password for the certificate.
     ironsoftwareofficial/ironsecuredoc:latest # Specifies the Docker image to use.
    # Runs the IronSecureDoc Docker container with both HTTP and HTTPS ports exposed.
    docker container run -d \
     -p 8081:8081 -p 8080:8080 \ # Maps container ports to host ports for HTTP and HTTPS.
     -e HTTP_PORTS=8080 \ # Sets the HTTP port for the application.
     -e HTTPS_PORTS=8081 \ # Sets the HTTPS port for the application.
     -e IronSecureDoc_LicenseKey=<IRONSECUREDOC_LICENSE_KEY> \ # Provides the IronSecureDoc license key.
     -e ENVIRONMENT=Production \ # Configures the environment as Production.
     -v %USERPROFILE%\.aspnet\https:/https:ro \ # Mounts the directory to the container as read-only.
     -e CERTIFICATE_PATH=%USERPROFILE%\.aspnet\https\ironsecuredoc.pfx \ # Specifies the path to the certificate in the container.
     -e CERTIFICATE_PASSWORD=<CERTIFICATE_PASSWORD> \ # Password for the certificate.
     ironsoftwareofficial/ironsecuredoc:latest # Specifies the Docker image to use.
    SHELL

    Replace <IRONSECUREDOC_LICENSE_KEY> and <CERTIFICATE_PASSWORD> with your actual IronSecureDoc license key and certificate password, respectively.

常见问题解答

为什么 HTTPS 对文档安全很重要?

HTTPS 对文档安全至关重要,因为它加密了传输的数据,确保敏感信息在传输过程中保持机密并防止拦截。

如何为我的应用程序创建 HTTPS 证书?

您可以通过运行命令dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>创建 HTTPS 证书,该命令生成用于 ASP.NET Core 的新证书。

怎样确保我的 HTTPS 证书在本地机器上被信任?

要在本地机器上信任您的 HTTPS 证书,使用命令dotnet dev-certs https --trust。此命令将您的系统配置为信任生成的证书。

运行支持 HTTPS 的 Docker 容器的过程是什么?

要运行支持 HTTPS 的 Docker 容器,开放 HTTP 和 HTTPS 端口,设置必要的环境变量如IronSecureDoc_LicenseKeyCERTIFICATE_PASSWORD,并将证书目录挂载为只读。

在 Docker 设置中应该配置哪些端口以支持 HTTPS?

在 Docker 设置中进行 HTTPS 配置,通过暴露端口 8081 作 HTTPS 和端口 8080 作 HTTP ,将容器端口映射到主机端口。

如何将证书密码传递给 Docker 容器?

在执行 Docker run 命令时,使用环境变量CERTIFICATE_PASSWORD将证书密码传递给 Docker 容器。

在 Docker 中配置为 "Production" 环境需要哪些步骤?

要在 Docker 中配置为“Production”环境,在您的 Docker run 命令中设置环境变量ENVIRONMENT=Production

在 Docker 命令中如何处理占位符?

在 Docker 命令中,用您的实际 IronSecureDoc 许可证密钥和证书密码替换占位符如<IRONSECUREDOC_LICENSE_KEY><CERTIFICATE_PASSWORD>以确保正常功能。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
版本: 2024.10 刚刚发布