Docker compose port forwarding Linux asp net core

0 votes

I have a handful of docker images that work fine. Except for the ports that are always 5000 (the default on asp.net core), everything works. I have tried multiple methods to get around this, but I am out of ideas now.

The containers are running on Debian 9- Hosted on Linode

Ran my build with

docker-compose -f docker-compose.yml up

My docker-compose.yml

#Api  Service
API:
 build:
  context: .
  #Use the DockerFile in that Directory
  dockerfile: Dockerfile
  #This Service Depends on the database service specifed above
  depends_on:
  - database
#Map port 8888 in the docker container to port 80 in the Api
ports:
  - "5000:80"
restart: always
#Specify Environment Variables for the Api Service
environment:
  - DBHOST=database
  - ASPNETCORE_ENVIRONMENT=Production


Content for DockerFile

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80/tcp

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

WORKDIR /src
COPY ["TestApi.csproj", "./"]
RUN dotnet restore "TestApi.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "TestApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "TestApi.csproj" -c Release -o /app/publish


FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "TestApi.dll"]


File content docker-compose.debug.yml

version: '3.4'

services:
  testapi:
    image: testapi
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 80
      - 5000
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_URLS=http://+:80
    volumes:
      - ~/.aspnet/https:/https:ro
Apr 20, 2022 in Docker by pranav
• 2,590 points
1,913 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Docker

+1 vote
4 answers

Docker compose, running containers in net:host

Hey@Hannah, Check the compose file format specifications ...READ MORE

answered May 7, 2019 in Docker by Kishore
4,955 views
0 votes
1 answer
0 votes
1 answer

How do I install docker-compose on linux?

Docker Compose is a tool for defining ...READ MORE

answered Jul 2, 2019 in Docker by Sirajul
• 59,230 points
9,378 views
+1 vote
5 answers

Set containers timezones by using docker compose.

version "2" services: serviceA: ...READ MORE

answered Jul 9, 2018 in Docker by Atul
• 10,240 points
22,793 views
0 votes
1 answer

How can I expose more than 1 port with Docker?

To expose just one port, this is ...READ MORE

answered Jul 25, 2018 in Docker by Kalgi
• 52,360 points
561 views
0 votes
1 answer

Interactive shell using Docker Compose

You need to include the following lines ...READ MORE

answered Jul 26, 2018 in Docker by Kalgi
• 52,360 points
6,185 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,090 points
2,477 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP