我的DockerFile:
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
#USER app
WORKDIR /app
EXPOSE 80/tcp
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Services/Catalog/Catalog.API/Catalog.API.csproj", "Services/Catalog/Catalog.API/"]
RUN dotnet restore "./Services/Catalog/Catalog.API/./Catalog.API.csproj"
COPY . .
WORKDIR "/src/Services/Catalog/Catalog.API"
RUN dotnet build "./Catalog.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Catalog.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Catalog.API.dll"]
字符串
我的docker-compose文件
version: '3.4'
services:
catalogdb:
container_name: cataloggdb
restart: always
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
catalog.api:
container_name: catalog.api
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "DatabaseSettings:ConnectionString=mongodb://catalogdb:27017"
depends_on:
- catalogdb
ports:
- "8000:80"
型
我执行
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d
✔ Network src_default Created 0.0s
✔ Container cataloggdb Started 0.1s
✔ Container catalog.api Started
型
x1c 0d1x的数据
当我转到http://localhost:27017/
时,它工作:
的
当我转到http://localhost:8000/swagger/index.html
时,它不工作:
的
1条答案
按热度按时间f45qwnt81#
EXPOSE
实际上并没有设置端口,它基本上是文档:EXPOSE
指令实际上并不发布端口,它的作用是作为构建镜像的人和运行容器的人之间的一种文档,关于哪些端口要发布。由于.NET 8在ASP.NET Core镜像中默认端口是
8080
-参见Default ASP.NET Core port changed from 80 to 8080
。或者更改Map以反映:
字符串
或者使用
ASPNETCORE_HTTP_PORTS
环境变量将端口设置为80
:型
或
型