USE HTTPS in C# by Running the Container with a Certificate

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

如果您需要使用證書運行容器,請按照以下步驟生成證書並配置本地機器:

使用憑證運行IronSecureDoc容器

  1. 生成證書

    # 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

    <CREDENTIAL_PLACEHOLDER>替換為密碼。

  2. 運行 Docker 容器

    # 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

    IronSecureDoc授權金鑰和憑證密碼。

常見問題

為什麼HTTPS對文件安全很重要?

HTTPS對文件安全至關重要,因為它加密傳輸中的資料,確保敏感資訊在傳輸過程中保持機密和防止截取。

我如何為我的應用程式建立HTTPS證書?

您可以通過執行命令dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\ironsecuredoc.pfx -p <CREDENTIAL_PLACEHOLDER>建立用於ASP.NET Core的新證書。

如何確保我的HTTPS證書在本地機器上被信任?

要在本地機器上信任您的HTTPS證書,請使用命令 dotnet dev-certs https --trust。此命令將配置系統以信任生成的證書。

運行支持HTTPS的Docker容器的過程是什麼?

要運行支持HTTPS的Docker容器,公開HTTP和HTTPS端口,設置必要的環境變數如IronSecureDoc_LicenseKeyCERTIFICATE_PASSWORD,並將證書目錄掛載為只讀。

在Docker設置中應該配置哪些端口以支持HTTPS?

在Docker設置中,通過公開8081端口支持HTTPS,8080端口支持HTTP來映射容器端口到主機端口。

如何將證書密碼傳遞給Docker容器?

當執行Docker run命令時,使用環境變數CERTIFICATE_PASSWORD將證書密碼傳遞給Docker容器。

配置Docker為'Production'環境需要哪些步驟?

要將Docker配置為'Production'環境,在Docker run命令中設置環境變數ENVIRONMENT=Production

在Docker命令中應如何處理佔位符?

在Docker命令中,將<IRONSECUREDOC_LICENSE_KEY><CERTIFICATE_PASSWORD>等佔位符替換為實際的IronSecureDoc授權金鑰和證書密碼以保證正常運行。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
版本: 2024.10 剛剛發布
Still Scrolling Icon

還在滾動嗎?

想要快速證明嗎?
運行一個樣本觀看您的PDF加密。