docker - 通过 docker-compose 和 docker registry 进行两个 Api 连接
问题描述
我们有一个带有 DockerFile 的 API 项目
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 43001
EXPOSE 43002
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY Api.csproj Api/
RUN dotnet restore Api/Api.csproj
COPY . .
WORKDIR /src/Api
RUN dotnet build Api.csproj --no-restore -c Release -o /app
FROM build AS publish
WORKDIR /src/Api
RUN dotnet publish Api.csproj --no-restore --no-self-contained -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Api.dll"]
与docker-compose
version: '3.5'
services:
Api:
image: Api
restart: always
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_ENVIRONMENT=Production
build:
context: .
dockerfile: Api/Dockerfile
ports:
- "43001:80"
- "43002:443"
该项目推送到私有 docker 注册表。
我们还有第二个 Prod 项目应该使用并连接到 Api 项目。
docker-compose
产品项目:
version: '3.5'
services:
Prod:
image: Prod
restart: always
environment:
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://+:80
build:
context: .
dockerfile: Prod/Dockerfile
depends_on:
- Api
networks:
- proxy-net
expose:
- "80"
Api:
image: {RegistryAddress}/Api
restart: always
networks:
- proxy-net
ports:
- "43002:443"
networks:
proxy-net:
external:
name: proxy-net
问题 - 当我从 Prod 连接到 Api 时,连接被拒绝。也许与端口设置有关,但我尝试了很多更改并没有帮助。我认为 Api 端口设置应该足够了,但看起来我们还需要在 Prod 中设置一些东西。
解决方案
推荐阅读
- docker - 我应该为 docker 托管的 DNS 解决方案禁用 systemd-resolve 吗?
- android - RecyclerView ViewHolder 的新 Activity 卡在黑屏上
- android - Android RecyclerView 触发背景选择器/波纹以获取一些滚动视图
- angular - 出现错误:NG0303:无法绑定到“ng-If”,因为它不是“app-grocery”的已知属性
- android-studio - 从具有 ViewPager2 的 Fragment 中的 Fragment 调用方法
- python - 如何解决“ValueError:无法从重复轴重新索引”?
- r - 如何在 r 中包含缺失的数据点
- node.js - 无法从 cookie 或标头访问 JWT
- javascript - 如何淡化带有重叠文本的标题
- firebase - Flutter + Firebase - 计算剩余时间