Compile Aspnet core 1.1 outside Docker container but run within
Prerequisite
OSX
A folder named (e.g.) /Users/yourname/Docker/Dandelion
and a folder named (e.g.) /Users/yourname/Docker/Dandelion/MyWeb
Create the web
In MyWeb run
1 2 3 4 | dotnet new -t web dotnet restore dotnet build dotnet publish |
Now we have a web site compiled and ready to run with [dotnet run].
You can run the app and then [curl localhost] to find out if it is runnable; but if you got no error message earlier all should be ok.
Create an image
Go to the Dandelion folder.
Create a file Dockerfile and paste into it:
1 2 3 | FROM microsoft/dotnet EXPOSE 80 ENV "ASPNETCORE_URLS=http://+:80" |
Then, to create the image run
1 | docker build -t yourname/dandelion . |
Note that the name must be all small caps.
Don’t miss the trailing period.
If you want to check that the image is created just execute [docker images] which should show the new image at the top of the list.
Start the container
Go to the Dandelion folder. (you are probably already standing there)
Execute
1 2 3 4 5 | docker run -p 80:80 \ -ti --rm \ -v /Users/yourname/Documents/Docker/Dandelion/MyWeb/bin/Debug/netcoreapp1.1/publish:/MyWeb \ yourname/dandelion \ /bin/bash -c 'cd /MyWeb; dotnet MyWeb.dll' |
and your web should start.
Verify result
Either open another console and execute
1 | curl localhost |
or go to localhost in your web browser.
Tags: .net-core, asp.net, asp.net core, container, docker