docker - Docker compose build 始终将 ENV 值设置为端口 80
问题描述
我有以下 dockerfile:-
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY ["src/CustomerManagement/CustomerAPI/CustomerAPI.csproj", "src/CustomerManagement/CustomerAPI/"]
COPY . .
WORKDIR "/src/src/CustomerManagement/CustomerAPI"
RUN dotnet build "CustomerAPI.csproj" -c Release -o /app
RUN dotnet restore -s https://api.nuget.org/v3/index.json -s https://www.myget.org/F/autoweb/api/v3/index.json
FROM build AS publish
RUN dotnet publish "CustomerAPI.csproj" -c Release -o /app
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS=http://*:5000
HEALTHCHECK --interval=30s --timeout=3s --retries=1 CMD curl --silent --fail http://localhost:5000/hc || exit 1
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "CustomerAPI.dll"]
Docker.compose 文件:-
customerapi:
image: ${DOCKER_REGISTRY-}customerapi
networks:
- backendpool
build:
context: .
dockerfile: src/CustomerManagement/CustomerAPI/Dockerfile
depends_on:
- sqlserver
- rabbitmq
ports:
- "5000"
environment:
- ASPNETCORE_ENVIRONMENT=Production
问题描述:-
我已指示 dockerfile 公开端口 5000。当我尝试构建 compose 文件时,它的构建很好,但它从不公开端口 5000。当我检查我的 docker 配置时,它总是设置为端口 80:-
docker 容器镜像配置:- pull through (docker inspect cli)
"DockerVersion": "19.03.1",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ASPNETCORE_URLS=http://+:80",
"DOTNET_RUNNING_IN_CONTAINER=true",
"ASPNETCORE_VERSION=2.2.6"
],
"Cmd": null,
"Image": "sha256:1632908f5f238edcea0e99468a1584b859d6593bcd7e2a8943233c8d2bd4b983",
"Volumes": null,
"WorkingDir": "/app",
"Entrypoint": [
"dotnet",
"CustomerAPI.dll"
],
"OnBuild": null,
"Labels": null
},
无论您在 ENV 键值对中设置什么值,它都不会以这种方式设置,并且我很难理解如何告诉 docker compose 文件将 ENV 值设置为 docker 文件中的公开端口???
启动 settings.json 文件:-
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5000",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "index.html",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"CustomerAPI": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "index.html",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5000"
}
}
}
docker-compose.local.yml
version: '3.5'
services:
customerapi:
ports:
- "5000:5000"
构建我的 docker 镜像容器
docker-compose -f docker-compose.yml -f docker-compose.local.yml build
解决方案
正确的顺序是这样
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "CustomerAPI.dll"]
推荐阅读
- php - 如何将我的 Laravel 页面重定向到我指定的页面?
- ios - 在 ScrollView 内缩放和滚动 ImageView
- javascript - AJAX 不会在我的 rails 应用程序中呈现我的购物车
- javascript - Nest 无法解析 NodeMailerService (?, AppConfigService) 的依赖关系
- vim - 如何打开可修改的文件
- node.js - Docker 容器 npm 错误!内部监视失败:检测到循环符号链接
- php - 无法访问 PHP 对象数组中的数据
- reactjs - 如何使用 React 根据其 ID 显示博客文章?
- php - 语法错误,在 Laravel 8 中调用“all()”或“get()”时出现意外标记“::”
- javascript - 具有动态参数的 Ag-grid 单元格编辑器:使用全局变量