构建脚本如下
FROM microsoft/aspnetcore-build as build-env
WORKDIR /code
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM microsoft/aspnetcore
WORKDIR /app
COPY --from=build-env /code/out ./
# 端口设置,要和程序中设置的监听端口保持一致
EXPOSE 80
# 运行后docker容器后,会在当前工作目录下默认执行的命令
ENTRYPOINT [ "dotnet","MyUserApi.dll" ]
执行构建命令
docker build -t myapi .
运行命令
docker run -d -p 8808:80 --name aspnetcoreweb --link=mysql01:db myapi
网友评论