Home > front end >  Umbraco v10 / dotnet vs Docker
Umbraco v10 / dotnet vs Docker

Time:06-27

I've been struggling with setting up umbraco 10 with Docker, so I was hoping you could push me in the right direction.

I have created a brand new Umbraco with the newest dotnet sdk installed on mac.

$ dotnet new umbraco --name Umbraco10Test

And then I can publish it by doing

$ dotnet publish Umbraco10Test.csproj --configuration Release --no-restore --output ./app
$ cd app
$ dotnet Umbraco10Test.dll

And then I can go to http://localhost:5000 and install my Umbraco. So far so good. And if in my appsettings.json file add:

 "Kestrel": {
   "Endpoints": {
     "properties": {
       "Url": "http://localhost:4000"  
     }
   } 
 }

I am able to change to port listening to 4000 instead of 5000.

Cool. Now I want to put it into Docker. I have created this Dockerfile.

########################
### build
########################
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

ARG PROJECT

WORKDIR /src

ENV PROJECT=${PROJECT}

COPY . .

RUN dotnet restore "${PROJECT}.csproj"

RUN dotnet publish "${PROJECT}.csproj" --configuration Release --no-restore --output /app

########################
### final
########################
FROM mcr.microsoft.com/dotnet/aspnet:6.0 

ARG PROJECT

WORKDIR /app

ENV ASPNETCORE_URLS "http://*:4000"

ENV DLL="${PROJECT}.dll"

COPY --from=build /app .

RUN echo "#!/bin/sh\ndotnet ${DLL}" > ./entrypoint.sh
RUN chmod  x ./entrypoint.sh

EXPOSE 4000

ENTRYPOINT ["./entrypoint.sh"]

And then I build and run the docker with this:

$ docker build --no-cache --progress=plain -t umbraco10test_docker --build-arg PROJECT=Umbraco10Test .
$ docker run --rm -d -p 4000:4000 --name umbraco10 umbraco10test_docker

If i try and go to http://localhost:4000 then I get a ERR_EMPTY_RESPONSE error page, and if I try to curl this I get a curl: (52) Empty reply from server

If I docker exec -it umbraco10 /bin/bash into the running container and try execute the same entrypoint.sh file created by the Dockerfile, I get this error:

Unhandled exception. System.IO.IOException: Failed to bind to address http://127.0.0.1:4000: address already in use.
 ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
 ---> System.Net.Sockets.SocketException (98): Address already in use
   at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)

So it seems to be runnning. I have a suspicion that it has to do with https and ssl, and another port or maybe 0.0.0.0 vs 127.0.0.1, but can figure it out. Hope you can help me :)

I have created a demo repo if anyone is interested :) https://github.com/lalunastudio/umbraco-10-docker-demo

// Peter

CodePudding user response:

In general, processes in Docker containers must listen on the special 0.0.0.0 "all interfaces" address. If they listen on 127.0.0.1, that binds to a container-private localhost interface, and your process will be reachable from neither another container nor the containing host.

In your case this means you need to change the listener URL

"Url": "http://0.0.0.0:4000"

Note that this will not be the address you use to contact the service. From another container on the same Docker network, use its container name or Compose service name and port 4000; from outside Docker but on the same host, use localhost and the first published port number (docker run -p or Compose ports: option); from a different host use the host's DNS name and the first published port number.

  • Related