Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter Nielsen 159 posts 257 karma points
    Jun 23, 2022 @ 10:21
    Peter Nielsen
    0

    Umbraco v10 + Docker

    Hi

    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 :)

    Cheers

    Peter

  • girish 15 posts 88 karma points
    Jun 23, 2022 @ 14:13
    girish
    0

    Hi Peter Nielsen,

    Just kill the process/port and try again.

    Otherwise Go to Project Properties > Deubg tab > Web Server Settings > App URL and add some different ports.

  • Peter Nielsen 159 posts 257 karma points
    Jun 23, 2022 @ 14:27
    Peter Nielsen
    0

    Hi Girish

    Ehm. Where? Inside the Docker container? :) Im not sure this is answering the right question, or is it just me? I was wondering what I did wrong, and why I could see the published version of my newly installed Umbraco inside af docker container. I can make it work in both debug and release mode on my machine :)

  • Peter Nielsen 159 posts 257 karma points
    Jun 26, 2022 @ 08:02
    Peter Nielsen
    0

    I have created a demo repo here, if anyone would like to take a crack at it

    https://github.com/lalunastudio/umbraco-10-docker-demo

  • Peter Nielsen 159 posts 257 karma points
    Jun 26, 2022 @ 20:31
    Peter Nielsen
    101

    Just if anybody else comes in here.

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

    Change localhost to 0.0.0.0 instead.

  • Johan Runsten 38 posts 277 karma points c-trib
    Jun 27, 2022 @ 06:40
    Johan Runsten
    0

    Hi!

    We're running U10 in docker containers in Azure and we use the following syntax to set the correct urls. There are a few ways to do it and what works in one environment might not work in another.. Just a heads up if you run into problems in production. Also see https://andrewlock.net/5-ways-to-set-the-urls-for-an-aspnetcore-app/ !

    Dev:

    ENV ASPNETCORE_URLS=http://+:5001 ENV ASPNETCORE_ENVIRONMENT=Development ENTRYPOINT dotnet watch

    Production:

    ENTRYPOINT dotnet ./Site.Web.dll --urls=http://+;https://+

Please Sign in or register to post replies

Write your reply to:

Draft