Teler
Teler

Reputation: 507

My docker-compose asp.net core project is not properly running, I get ERR_CONNECTION_REFUSED

I have a small web service that I wrote in asp.net core 2.2, Im using docker-compose for this project but I cant get it to work properly, everytime I try to run it I get the ERR_CONNECTION_REFUSED and it doesnt show my Swagger documentation. For now Im just using the self generated docker file from Visual Studio because I want to get at least my Swagger documentation so It doesnt show the ERR_CONNECTION_REFUSED error. When I do docker ps it shows the following:

enter image description here

So I know the container is up and running.

My docker file:

FROM microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.2-sdk-stretch AS build
WORKDIR /src
COPY AppointmentsAPI/AppointmentsAPI.csproj AppointmentsAPI/
RUN dotnet restore AppointmentsAPI/AppointmentsAPI.csproj
COPY . .
WORKDIR /src/AppointmentsAPI
RUN dotnet build AppointmentsAPI.csproj -c Release -o /app

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

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

Docker-Compose file:

version: '3.4'

services:
  appointmentsapi:
    image: ${DOCKER_REGISTRY-}appointmentsapi
    build:
      context: .
      dockerfile: AppointmentsAPI/Dockerfile

As you guys can see everything is self generated by visual studio, so it should work, I only want to be able to see my documentation or at least have it working and after that I will add the other things.

Upvotes: 1

Views: 1717

Answers (2)

D. Vinson
D. Vinson

Reputation: 1158

Try adding port 80 to Compose file. You are exposing port in dockerfile which will work with docker run -p 80:80 .... Using compose you need to map the port.

version: '3.4'
services: 
  appointmentsapi:
    image: ${DOCKER_REGISTRY-appointmentsapi
    build: 
      context: .
      dockerfile: AppointmentsAPI/Dockerfile
    ports:
      - 80:80

you can Map 80 to whatever you want or let docker map it for you.

Let Docker map external port:

ports: 
  - 80

Map port 80 to external 3000

ports:
  - 80:3000

UPDATE:

running VirtualBox and needed to use the VirtualBox IP rather than localhost.

Using the virtual box IP and adding port mapping to the compose file should resolve the issue.

Upvotes: 2

Black Hole
Black Hole

Reputation: 1382

the ports and the firewall, check it, because docker make a owns network

Upvotes: 0

Related Questions