Last active
October 1, 2025 02:21
-
-
Save relyky/184658c0c1f5583c8fcf4d375df72597 to your computer and use it in GitHub Desktop.
docker 指令紀錄 in 2025, for NET8, React and ASP.NET Core 專案部署紀錄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker 環境專用的設定檔 | |
# ASP.NET Core 會自動將 : 轉換為階層 | |
ConnectionStrings:AUCDB=Server=host.docker.internal,1433;Database=AuctionDB;User Id=sa;Password=*******;Encrypt=false | |
ConnectionStrings:YourDB=Server=host.docker.internal,1433;Database=YourDbName;User Id=sa;Password=*******;Encrypt=false | |
# 您也可以在這裡加入或覆寫其他設定,例如: | |
# Logging:LogLevel:Default="Information" | |
# SomeOtherKey="SomeValue" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Docker 部署指令紀錄 | |
# - 此例是用在部署 NET8 React in ASP.NET Web App 到 Docker Desktop。 | |
# - 此例部署到 Docker Desktop 是 HTTP 模式。若要支援 HTTPS 需再加入 TLS/SSL 憑證與相關組態。 | |
# (prefix) | |
# - 前置工作:先手動發行專案到 `_publish` 目錄。 | |
# - 前置工作:切換到專案根目錄。加入 `Dockerfile` 並填寫組態。 | |
# (CI) | |
# build (此例 build 只是複製檔案到 docker) | |
# - 將依組態檔 `Dockerfile` 進行 build。 | |
docker build -t auctionhouseapp . | |
docker build -t <your-webapp-image-name> <source_folder> | |
# (CD) | |
# 啟動並依 ./docker.env 參數啟動(以虛網啟動) | |
# - 其中 -p 38080:8080 --- 轉換內部虛網 port 8080 → 外部 port 38080 | |
# - 其中 --env-file 指向環境參數檔。會取代 appsetting.json 對應的參數。也可用 `-e ...` 語法替換。 | |
docker run -d -p 38080:8080 --name auctionhouse-container --env-file ./docker.env auctionhouseapp | |
docker run -d -p 38080:8080 --name <your-webapp-container-name> --env-file ./docker.env <your-webapp-image-name> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 使用官方的 ASP.NET Core 執行階段作為基礎映像 | |
FROM mcr.microsoft.com/dotnet/aspnet:8.0 | |
# 在容器內建立一個工作目錄 | |
WORKDIR /app | |
# 將 _publish 目錄中的所有檔案複製到容器的 /app 目錄中 | |
# - 前置工作:先手動發行專案到 `_publish` 目錄。 | |
# - ※此例在前置工作就編譯完成。此步驟只是複製到 docker image。 | |
COPY ["_publish/", "."] | |
# 公開容器的 8080 連接埠,讓外部可以存取 | |
EXPOSE 8080 | |
# 設定容器啟動時執行的命令 | |
# 這裡假設您的啟動專案是 AuctionHouseApp.Server.dll | |
ENTRYPOINT ["dotnet", "AuctionHouseApp.Server.dll"] |
Comments are disabled for this gist.