【发布时间】:2019-12-30 13:13:39
【问题描述】:
我有以下 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
【问题讨论】:
-
端口:- "5000:5000"
-
已经在 docker-compose.local.yml 中设置 版本:'3.5' services: customerapi: ports: - "5000:5000"
-
docker-compose -f docker-compose -f docker-compose.local.yml 构建
-
我只能在你的配置中看到端口 5000
-
我已经粘贴了启动设置.json,你可以检查一下!!
标签: docker asp.net-core asp.net-web-api docker-compose dockerfile