ASP.NET Core Runtime Docker Image
This repository contains images for running published ASP.NET Core applications. These images use the
microsoft/dotnet image as its base.
These images contain the runtime only. Use microsoft/aspnetcore-build to build ASP.NET Core apps inside the container.
Supported tags
1.0.5,1.0,lts1.1.2,1.1,12.0.0-preview2,2.0,22.0.0-preview2-jessie, '2.0-jessie', '2-jessie' (Dockerfile)
What is ASP.NET Core?
ASP.NET Core is a new open-source and cross-platform framework for building modern cloud based internet connected applications, such as web apps, IoT apps and mobile backends. It consists of modular components with minimal overhead, so you retain flexibility while constructing your solutions. You can develop and run your ASP.NET Core apps cross-platform on Windows, Mac and Linux. ASP.NET Core is open source at GitHub.
This image contains:
- .NET Core so that you can run your already compiled .NET Core applications.
- A set of native images for all of the ASP.NET Core libraries. These images will be used at runtime to increase
the cold-start performance of your application. A significant amount of the time taken to JIT compile on startup of
your application is typically spent compiling ASP.NET Core libraries rather than your application code. Given that
these libraries are not going to change for a given version we include native images so that the runtime can load them
instead of running the JIT.
Related images
- microsoft/dotnet - the .NET Core image if you don't need the ASP.NET Core specific optimizations.
- microsoft/aspnetcore-build - The ASP.NET Core build image for publishing an ASP.NET Core app inside a container.
How to use this image
Create a Dockerfile for your application, the following example assumes you have already compiled your application (which is the expected use case for this image)
FROM microsoft/aspnetcore WORKDIR /app COPY . . ENTRYPOINT ["dotnet", "myapp.dll"]Build and run your app:
$ docker build -t myapp . $ docker run -d -p 8000:80 myappBrowse to localhost:8000 to access your app.
A note on ports
This image sets the ASPNETCORE_URLS environment variable to http://+:80 which means that if you have not explicity
set a URL in your application, via app.UseUrl in your Program.cs for example, then your application will be listening
on port 80 inside the container.
is it possible to have session replication among a set of containers?
If you are using Windows 2016 as host, you should do the following (latest version does not work because there is not support for linux):
- docker pull microsoft/aspnetcore:1.1.2-nanoserver
Create your WebApp (I used VS2017 and Core 1.2 wihout docker support, again does not work on Windows Server 2016) then publish using default parameters. It will create a directory PublishOutput on release directory. Add Dockerfile on release directory as follows:
FROM microsoft/aspnetcore:1.1.2-nanoserver
WORKDIR /app
COPY ./PublishOutput /app
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Run these commands:
- docker build -t webapp .
- docker run -d -p 80:80 webapp
For some reason you cannot use http://localhost for seeing your web app. You need container IP. You need to run command (if it is the only container):
- docker inspect $(docker ps -q)
My output:
"EndpointID": "26015931ad561763f7918e67875478d5d607ae0fb3a298e7d2dcd1641653ec93",
"Gateway": "172.19.16.1",
"IPAddress": "172.19.19.244",
"IPPrefixLen": 16,
So IPAddress assigned to container in my case is 172.19.19.244.
Using this IP on my browser I could reach my Web App finally :)
It is better to create issues on https://github.com/aspnet/aspnet-docker to get help rather than comments here. @danj210, I think you got help there right?
No matter what I cannot get the container to run for the life of me even when I follow the instructions exactly below. Container exits with error code (134).
I've published exactly as shown below. I'm using the copy exactly as shown below with the above few lines in the Dockerfile, my entry point is exactly as shown below and I've tried a few different combinations but no matter what, the container will not run.
You have to publish your source code first. Otherwise it will not work:
- dotnet publish -o:./published
This will copy your app into published folder and then you have to COPY published app:
- COPY ./published /app
And then entrypoint will work:
- ENTRYPOINT ["dotnet", "myapp.dll"]
How can I change the user?
I am trying this:
RUN addgroup $USER && adduser -shell /bin/bash -D -G $USER $USER
and it gives error
@liuxm6 This means the .dll file isn't where you've specified. The following things must be correct for the image to work:
The dll must be in the root
The COPY operation with . . copies from the current working directory of your PC to the working directory (/app) in the container. If your output .dll file is somewhere else you'll need to update the first . to the path where the output directory is.
For example: COPY output/mywebsite .
Alternatively, if you're using a sub directory, make sure to specify the full path in the ENTRYPOINT command.
For example:
ENTRYPOINT ["dotnet", "app/myapp.dll"]
The website must be in the /app folder.
The WORKDIR command does this. I tried renaming it, but that broke the runtime
Output directory must be a sub directory, or absolute
With the current .NET build tools (I think fixed in preview 3), the output directory of the dotnet publish command must be a sub directory of the project, or specified absolutely. If you use a relative path (../) the publish parameters will be ignored and you won't get your views, etc.
To use dotnet run, please use microsoft/aspnetcore-build instead. This image only contains the runtime.
Also, we are unlikely to see comments and questions here. Please post issues on https://github.com/aspnet/aspnet-docker instead.
docker run -d -p 8000:80 myapp
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
@stanuku THANK YOU SO MUCH!