1、参考
- https://learn.microsoft.com/en-us/dotnet/core/docker/build-container?tabs=linux&pivots=dotnet-8-0
- 多阶段构建docker镜像
2、Dockerfle
# Learn about building .NET container images:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
# ARG 硬件架构
ARG TARGETARCH
WORKDIR /source
# copy csproj and restore as distinct layers
COPY aspnetapp/*.csproj .
RUN dotnet restore -a $TARGETARCH
# copy and publish app and libraries
COPY aspnetapp/. .
RUN dotnet publish --no-restore -a $TARGETARCH -o /app -f net8.0
# Enable globalization and time zones:
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
EXPOSE 8080
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["./WebApplication2"]
3、命令
··· docker build -t net8-demo .
docker run --restart always -itd --name net8-d -p 8000:8080 net8-demo
docker exec -it net8-d /bin/bash
docker logs net8-d
docker run --restart always -itd --name ak-1 -p 11000:8080 ak
docker build -t ak-basic -f Dockerfile-Basic .
docker run --restart always -itd --name ak2 -p 11001:8080 ak-basic ···
nginx
docker run -d --name nginx --network mynetwork -p 80:80 -v /path/to/nginx/conf:/etc/nginx/conf.d nginx
docker run --restart always -itd --name nginx -p 80:80 -v /root/github/NET8.0/nginx.conf:/etc/nginx/conf.d/dvs.conf nginx
docker run --restart always -itd --name nginx -p 8080:80 -v /root/github/NET8.0/nginx.conf:/etc/nginx/conf.d/default.conf nginx
// 创建容器专属网络
docker network create -d bridge aehyok