4

I am using docker-compose to host a .Net Core Web application created using the template from .Net Core.

I have my docker-compose as follows:

version: '3.4'

services:
  db:
    image: mysql:5.7
    container_name: mysql_db
    volumes: 
       - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_HOST: "localhost"
      MYSQL_ROOT_HOST: "%"

  todoservice:
    image: ${DOCKER_REGISTRY}todoservice
    ports: 
      - "8000:80"
    build:
      context: .
      dockerfile: ToDoService/Dockerfile
    depends_on:
      - db

volumes:
  db_data: 

In which I declare that my host machines port of 8000 will map to port 80 on this docker container. As well I have this dockerfile that defines how to build my .Net Core Web Api.

FROM microsoft/aspnetcore:2.0 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY ToDoService/ToDoService.csproj ToDoService/
RUN dotnet restore ToDoService/ToDoService.csproj
COPY . .
WORKDIR /src/ToDoService
RUN dotnet build ToDoService.csproj -c Release -o /app

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

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

After I run docker-compose up -d I see that my ToDoService is listing this information for PORTS:

0.0.0.0:8000->80/tcp, 0.0.0.0:32772->80/tcp

So where is that random 32772 port assignment coming from?

Bailey Miller
  • 1,220
  • 2
  • 16
  • 34

1 Answers1

0

When I specify the :443 it runs the debug (docker compose set to VS) consistently using the port I set (here I picked my port as 51836). Also I get the Swagger endpoint on the same port: https://localhost:51836/swagger/index.html

My docker-compose.yml:

version: '3.4'

services:

  company.api.authservices:
    image: ${DOCKER_REGISTRY-}company-api-auth-services
    build:
      context: .
      dockerfile: Company.Api.AuthServices/Dockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
    ports:
      - "51830:80"
      - "51836:443"