问题
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
回答1:
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/
来源:https://stackoverflow.com/questions/33462774/asp-net-5-0-beta-8-in-docker-doesnt-start