'Docker compose build always set ENV Value to port 80
I have following 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 file:-
customerapi:
image: ${DOCKER_REGISTRY-}customerapi
networks:
- backendpool
build:
context: .
dockerfile: src/CustomerManagement/CustomerAPI/Dockerfile
depends_on:
- sqlserver
- rabbitmq
ports:
- "5000"
environment:
- ASPNETCORE_ENVIRONMENT=Production
Problem descriptions:-
I have instructed dockerfile to expose port 5000. When i tried to build the compose file its build fine but it never expose port 5000. When I checked my docker configuration, it always set to port 80:-
docker container image configuration:- 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
},
No matter what value you set in ENV key-value pair, it never sets this way and m pretty much struggling to understand how to tell docker compose file to set ENV value to a expose port in docker file???
launch settings.json file:-
{
"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"
building my docker image container
docker-compose -f docker-compose.yml -f docker-compose.local.yml build
Solution 1:[1]
The correct sequence is this
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "CustomerAPI.dll"]
Solution 2:[2]
You have to set the following environment variable inside the docker-compose file, in order to listen to the preferred port.
ENV ASPNETCORE_URLS=http://+:5000
Solution 3:[3]
Expose the port after the process finishes the multistage operation
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "CustomerAPI.dll"]
EXPOSE 5000/tcp
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Soumen Mukherjee |
| Solution 2 | Mehdi Okhovat |
| Solution 3 | Adiii |
