Docker container with ASP.NET Core libraries

2019-09-09 22:53发布

问题:

Each time I build Dockerfile with ASP.NET Core application it's download assemblies from web Nuget store.

Basically I'd like to create docker image with all this ASP.NET Core libraries (and probably some libraries I usually use).

From my understanding I trying to reinvent GAC.

So, my question is it possible to use something like GAC for ASP.NET Core? Or, my second thought, download ASP.NET Core libraries to container and then resolve it locally somehow.

My goal is to reduse time for building docker container.

UPDATE

Looks like it's impossible

回答1:

There is now an official .NET Core Docker image from Microsoft, with all the needed libraries.

You can get it here:

https://hub.docker.com/r/microsoft/aspnetcore/

If you need to customize it, don't forget you can modify the container and create a custom image with "docker commit".



回答2:

For ASP.NET core just use dnu to build your application into a self-contained folder.

dnu publish 

will output build the project and output it to /bin/output. There are a number of options at your disposal including the ability to specify the output path, choose framework or runtime and even to change the command for starting the web.

dnu publish --help

will give you more detail on that.



回答3:

If you want to contain a "package" (folder) that contains your application, its dependencies and the runtime then you have to run:

dnu publish --runtime <active/runtime name> [--no-source]

The --no-source option compiles everything and increases the startup time but removes the ability to change the code in the container.