Run Docker Dotnet core aspnet 1.1 web server with mounted executable on OSX

Prerequisite

Install docker.

Install Dotnet Core 1.1.

Create web application

Create a directory “theapp”.

Open a terminal and, in the directory, execute:

1
2
3
dotnet new -t web
dotnet restore
dotnet run

Check it works.

Execute, in a terminal:

1
curl localhost

Or is it

1
curl localhost:5000

?

Create container

In a terminal execute:
(after you have have updated “YourRootedPathAndFolder” appropriately.

1
2
3
4
5
6
docker run -p 80:80 \
-e "ASPNETCORE_URLS=http://+:80" \
-ti --rm \
-v /YourRootedPathAndFolder/TheApp:/theapp \
microft/dotnet \
/bin/bash -c 'cd /theapp; dotnet restore; dotnet run'

and when it is finished churning through the long list of modules open a new terminal and execute

1
curl localhost

on your host to receive a smaller waterfall of HTML.

That should be it.

Troubleshooting

If you forget to do the dotnet restore

1
2
3
4
docker run -p 80:80 \
-ti -v /Users/ola/Documents/Docker/loose/TheApp:/theapp \
microsoft/dotnet \
/bin/bash -c 'cd /theapp; dotnet run'

You get something like:

Project theapp (.NETCoreApp,Version=v1.1) was previously compiled. Skipping compilation.

Error: assembly specified in the dependencies manifest was not found — package: ‘Microsoft.AspNetCore.Antiforgery’, version: ‘1.0.1’, path: ‘lib/netstandard1.3/Microsoft.AspNetCore.Antiforgery.dll’

Attach and request

Run

1
docker ps

in a terminal. Note the Container ID.

Then execute, after the b5a…f5 is updated appropriately.

1
docker exec -it b5a8ccd5b1f5 bash

Now you have a shell inside the container and should be able to get a result from:

1
curl localhost:5000

Tags: , , , , ,

Leave a Reply