ASP.NET 5.0 beta 8 in Docker doesn't start
Asked Answered
M

2

2

I have been running a website using ASP.NET 5.0 beta 7 in a Docker container, using the official Docker image - https://github.com/aspnet/aspnet-docker - which was working fine.

I recently updated my project to beta 8, and changed the Dockerfile to use the beta 8 version of the Docker image. Everything works fine when I run it locally on my Windows machine, whether I use Visual Studio to start the project with IIS Express, or run it using Kestrel.

However, then I push it to my Dokku server, it doesn't seem to start properly. I don't get any errors from the container output, but I have a CHECKS file which Dokku uses to ensure the web server has started, and this fails (indicating it hasn't started properly, or is not listening as it should be). I tried removing the CHECKS and I cannot connect to it either - I get a bad gateway message from nginx.

I don't know why this is happening, because when I push to Dokku, I get the following response:

...
remote: [1G-----> Attempt 5/5 Waiting for 10 seconds ...[K
remote: [1G       CHECKS expected result:[K
remote: [1G       http://localhost/ => "My Website"[K

remote: Could not start due to 1 failed checks.[K
remote: [1G !    [K
remote: [1Gcurl: (7) Failed to connect to 172.17.2.14 port 5000: Connection     refused[K
remote: [1G !    Check attempt 5/5 failed.[K
remote: [1G=====> mywebsite container output:[K
remote: [1G       info    :     [Microsoft.Framework.DependencyInjection.DataProtectionServices] User profile is     available. Using '/root/.local/share/ASP.NET/DataProtection-Keys' as key repository; keys will not be encrypted at rest.[K

remote: [1G       Hosting environment: Production[K
remote: [1G       Now listening on: http://localhost:5000[K
remote: [1G       Application started. Press Ctrl+C to shut down.[K
remote: [1G=====> end mywebsite container output[K`
...

This seems odd because it looks like it is starting, but after the checks have failed. As I said, removing the checks means it deploys successfully but then I'm unable to connect to it.

My Dockerfile is:

FROM microsoft/aspnet:1.0.0-beta8

# Install NPM
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs

# Install Gulp
RUN npm install -g gulp

COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]

WORKDIR ./src/mywebsite

RUN ["npm", "install"]
RUN ["gulp", "min"]

EXPOSE 5000
ENTRYPOINT dnx kestrel
Marjoram answered 1/11, 2015 at 13:42 Comment(0)
L
6

I ran into a similar issue where I couldn't access my ASP.NET 5 beta 8 website running in a Docker container on Windows, I was getting the same message as you.

I'm not sure if this will be the same issue for you, but here's how I fixed it on my end. The symptoms looks similar. The issue was related to this line here:

Now listening on: http://localhost:5000

The interesting thing is when I did a docker ps it showed that port 5000 was being forwarded on 0.0.0.0, not localhost.

The Solution

The way I fixed this was to update my web command in project.json to specify the actual network interface to use:

"commands": {
  "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000",
  "ef": "EntityFramework.Commands"
},

Once I did this, I could see that Kestrel was now listening on the same interface that Docker was forwarding for me and I was able to access the website without any problems.

Alternative using Dockerfile

You can also just update your ENTRYPOINT command in your Dockerfile:

ENTRYPOINT ["dnx", "web", "--server.urls", "http://0.0.0.0:5000"]

(You'll want to replace 0.0.0.0 with the exact interface that Docker is exposing).

Blog Post / Writeup

If you want to read more about this (or how to run Docker on Windows with ASP.NET 5), take a look at my blog writeup here: http://dotnetliberty.com/index.php/2015/10/25/asp-net-5-running-in-docker-on-windows/

Lacquer answered 1/11, 2015 at 23:10 Comment(4)
Changing the last line of my Dockerfile to ENTRYPOINT dnx kestrel --server.urls http://0.0.0.0:5000 worked, thanks!Marjoram
Hey, great. Glad to hear it helped.Lacquer
Thanks! It took me a few hours and your post to find out why I couldn't access Kestrel in my container.Doubleedged
This also happened to me on ubuntu. Adding --server.urls http://0.0.0.0:5000 in my project.json as specified above worked for me. When starting docker, be sure to specify -p 80:5000 option so that it can set up the port forwarding.Atticism
T
0

For me the problem was that i had in my appsettings: "Urls": "http://localhost:5000"

Even when i commented out the UseUrls() in the Program.cs where i was using it, it was still getting the url from the appsettings.json automatically.

I changed the value in appsettings.json to: "Urls": "http://+:5000" and now my app is accessible from outside the container to whatever port i forward it to: -p 5555:5000

This way i can access it through localhost:5555

Thremmatology answered 21/8, 2022 at 20:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.