Public | Automated Build

Last pushed: 3 days ago
Short Description
Official images for running compiled ASP.NET Core applications.
Full Description

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

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

  1. microsoft/dotnet - the .NET Core image if you don't need the ASP.NET Core specific optimizations.
  2. microsoft/aspnetcore-build - The ASP.NET Core build image for publishing an ASP.NET Core app inside a container.

How to use this image

  1. 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"]
    
  2. Build and run your app:

    $ docker build -t myapp .
    $ docker run -d -p 8000:80 myapp
    
  3. Browse 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.

Docker Pull Command
Owner
microsoft
Source Repository

Comments (12)
mkardash
8 days ago

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"]
ablancor
2 months ago

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

danclarke
2 months ago

@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.

natemcmaster
3 months ago

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.

liuxm6
3 months ago

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

northcoding
3 months ago

@stanuku THANK YOU SO MUCH!

stanuku
3 months ago

This works fine instead:

FROM microsoft/dotnet
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
EXPOSE 5000
ENTRYPOINT ["dotnet", "run"]

stanuku
3 months ago

I get this message.
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

eapyl
4 months ago

I used the next set of commands:

  1. docker publish -c Release -o ./app
    // publishing our application to app folder. The name of my application name is "hw", so I have hw.dll in app folder
  2. Used the next dockerfile:
    FROM microsoft/aspnetcore
    WORKDIR /app
    COPY ./app .
    ENTRYPOINT ["dotnet", "hw.dll"]
  3. Done
xin3222634
4 months ago

So I need to:

  1. Build && publish with microsoft/aspnetcore-build
  2. Run my published app with microsoft/aspnetcore
    Is that right?