Create and run an Aspnet core 1.1 web site in Docker container on OSX

January 7th, 2017

Prerequisite:

Docker and Dotnet Core 1.1 should be installed on the host (=OSX).

You have a folder somewhere, for instance /User/yourname/Documents/Docker/mywebapp.

Create the image

In your folder, create the dockerfile

1
2
3
4
5
6
7
8
FROM microsoft/dotnet
# VOLUME /Documents/Docker/mywebapp
EXPOSE 80
ENV "ASPNETCORE_URLS=http://+:80"
RUN mkdir app
WORKDIR /app
RUN dotnet new -t web
RUN dotnet restore

Then execute

1
docker build -t mynick/myimage .

in a terminal in said folder.

If you now execute

1
docker images

you can se the new image as mynick/myimage.

Create the container and start the web server

In the terminal execute

1
2
3
4
docker run \
-p 80:80 \
-ti --rm mynick/myimage \
/bin/bash -c 'cd /app; dotnet run;'

Behold result

In a terminal execute

1
curl localhost

or in a web browser go to

1
localhost

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

January 3rd, 2017

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

Create a Dotnet aspnet core 1.1 web server in OSX

December 31st, 2016

Install Dotnet core à la https://www.microsoft.com/net/core#macos

Create a folder and to to it.

Open a terminal (one cannot reuse any terminal from before dotnet was installed since the path is updated) and execute:

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

Open another terminal and execute:

1
curl localhost:5000

A pile of HTML should scroll into view.

In the first terminal you can see the reaction.

Running Dotnet aspnet 1.1 in a Docker container on OSX without any Windows

December 29th, 2016

Prerequisite

Install Docker on OSX.

Create Dockerfile

Create a file named Dockerfile in a new folder.
Its contents are:

1
2
3
4
5
6
7
8
FROM microsoft/dotnet
# VOLUME /Documents/Docker/dnc
EXPOSE 80
ENV "ASPNETCORE_URLS=http://+:80"
RUN mkdir app
WORKDIR /app
RUN dotnet new -t web
RUN dotnet restore

Create image

1
docker build -t yournick/yourimagename .

Run image

1
2
3
docker run -p 80:80 \
-ti --rm yournick/yourimagename \
/bin/bash -c 'dotnet run'

See output

On the host:

1
curl localhost

and you should se a whole dab of HTMl. You can also watch it in your browser.

Starting Dotnet aspnet core 1.1 on OSX in a Docker container

December 27th, 2016

Install Docker on OSX.

https://docs.docker.com/docker-for-mac/

Prepare local drive

(This is strictly not necessary but if you skip this you have to remove the -v and following path from the docker run command further down. You will also have to mkdir the app folder in the container before cd to it.)

Go to you your local Documents folder. Create a Docker folder. Inside it create a dotnetcore folder. This results in /Users/myname/Documents/Docker/dotnetcore.

Start container

Open a terminal and execute (after exchanging “myname” to your user’s name)

1
2
3
4
docker run -p 80:80 \
-e "ASPNETCORE_URLS=http://+:80" \
-v "/Users/myname/Documents/Docker/dotnetcore:/app" \
-it --rm microsoft/dotnet

This will download the microsoft/dotnet image, start it, connect your host’s dotnetcore folder to an app folder inside the container, set an environment variable, publish the internal port 80 on port 80 and finally open a terminal inside the container; all in one go.

Start the web server

Now inside the container execute

1
2
3
cd app
dotnet new -t web
dotnet restore

Absolutely not necessary but if you

1
cat Program.cs

you will see something like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace WebApplication
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
// .UseUrls("http://0.0.0.0:8000")
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}

Start the web server through

1
dotnet run

This will also compile the code before starting the application.

See output

If you open

1
http://localhost

in your host’s web browser you should now see a page about Dotnet aspnet core.

That all there is to it!

Trouble shooting

If you don’t check that the web server is running and listening on port 80 locally. This is done by opening a new terminal and check the ContainerID through

1
docker sp

Then you attach a terminal to the running container.

1
docker exec -it d10988067ec8 bash

(but with proper id)

Now, inside the container, run

1
curl localhost

and you should get a boatload of HTML back. In the other terminal window you should see some reaction to the request.

Links

More thourough but for version 1.0

https://store.docker.com/images/6c038a68-be47-4d7e-bfd2-33a6fe75b9ac?tab=description

Learn children to be a producer of content and not only a consumer on a tablet

November 30th, 2016

A tablet is not only for onsuming what other people have done. You can too. Also a kid can.

Bloxels

Create your own side scroller.

There is also hardware if you want.

http://www.bloxelsbuilder.com/

Coda game

I have not tested

http://filimundus.com/coda-game/

Daisy the dinosaur

There is not a clear goal, just fiddle around. For good and bad. It is like making movies in ScratchJr but only side scrolling and less effects.

http://daisythedinosaur.com/

The Foos

It is like Lightbot but side scrolling and with funnier characters. The goal is somewhat funnier compared to lightbot; getting a donut for a (US) police officer instead of just lighting a light bulb. To try it out there is an older? version on the web.

http://thefoos.com/play/

Hopscotch

Like Scratch.

https://www.gethopscotch.com/

Hour of code

Lots of stuff.

https://code.org/

Lego Minecraft

Hard to use computer interface.

Expensive.

Light bot

Make a little robot find her way around stairs and obstacles.

https://lightbot.com

Light bot looking but with famous figures like angry birds

https://studio.code.org/hoc/1

Minecraft (pocket edition)

https://minecraft.net/pocket

Scratch(Jr)

Unlogical user interface.

https://scratch.mit.edu/

Also see https://www.dexterindustries.com/BrickPi/program-it/scratch/ for using Scratch with Raspberrypi.

More mechanical than programming

Pettson and Findus

http://filimundus.com/pettsons-inventions/
http://filimundus.com/pettsons-inventions-2/
https://filimundus.com/pettsons-inventions-3/

Inventioneers

http://filimundus.com/inventioneers/

I have not tested

Cargo-bot

https://itunes.apple.com/us/app/cargo-bot/id519690804

Tynker

I have not tested.

https://www.tynker.com/

Move the turtle

itunes.apple.com/us/app/move-turtle.-programming-for/id509013878?mt=8

On a proper computer

Blockly

https://blockly-games.appspot.com/?lang=en

Quit skype with alt-F4 (Autohotkey needed)

October 20th, 2016

Due to overzealous user interface design Skype does not close with alt-F4 but instead minimises. That is not considered good behaviour.

I have found no setting in Skype to restore it normal Windows behaviour.

So I found and copied a Authotkey script that restores makes alt-F4 properly close Skype.

1
2
3
4
5
6
#IfWinActive ahk_exe Skype.exe ahk_class tSkMainForm
!f4::
WinClose
ExitApp
Return
#IfWinActive

Kudos to original article https://autohotkey.com/board/topic/126066-script-to-run-skype-with-real-alt-f4/

When code reviewing – do not forget to give appraisal too

September 29th, 2016

Albeit code reviewing is for the greater good and we all adhere to the idea of common ownage of code we are still critisising someone else’s labour.

Psychologically we cannot neglect that.

Ergo: remember to tell about the good solutions and code you find.

Unfortunately TFS does not have a (good) solution for differentiating between comments and praise and critisism.

AutoMapper does not play well with multi tier architecture

September 27th, 2016

I have found out that Automapper needs to be set up once and only once.
This means that one place has to know of all the classes that have a mapping. In a multi tier application this is not possible without treading on someone’s toes.

I have seen a solution which loops through all loaded assemblies and maps once and for all. But this solution means we have one such point – like when a web app is loading. So if you have automatic tests, that setup has to be called from there. And any kind of automatic loading of assemblies cannot use Automapper. Well… if one reinitialises all mappings one can.

I might see another solution where one has one assembly that knows of all assemblies (with mapping) and makes sure Automapper is initialised. My experimentation with this lead to circular reference problem though.

When I am at it – the documentation is short and straight to the point (good) but misses the point that the code in the documentation should be usable (not good).

The API was not explorable, which means that there is no natural way to start mapping and find out how the API works as one goes. Instead I had to google and find a bit here and a bit there.

With that said – it still solved a problem for me. And that is considered good.

Resharper and Visual studio short cuts

August 30th, 2016

There are some I use that might be useful for my readers too:

Resharper has 3 main combinations.
shift-alt-enter – Somewhat resembles Visual studio’s ctrl-..
ctrl-shift-r – Refactoring. Resharper’s raison d’être.
alt-ins – Inserting stuff by templates. E.g. a constructor taking all properties as arguments or Equal and GetHashCode methods.

ctrl-alt-q – Quickview instead of shift-f9

ctrl-w – Mark whatever you’re at. It can be set to recognise Pascal/camel cased words too as one often wants to edit just a part of a variable name.
Here’s a nice touch: continue press ctrl-w and the mark extends. A super way to mark a method.

ctrl-f12 – Go to implementation (instead of declaration). Often ctrl-f12 is enough.

alt-f12 – Sneak peak of whatever you are standing on. A good way to look at a called method body without having to  open yet a window, or move in an existing.
Here’s a nice touch: the opened sneak peak is a full fledged editor so go ahead and navigate, edit, debug and edit-and-continue as you are used to.

Above the method name (VS2015) there is a row with information about callers, editors, tests and whatnot. Hover over them with the mouse pointer and you get the shortcuts. They are typically ctrl-alt-1, ctrl-alt-2 und so weiter.

ctrl– and ctrl-+ – Navigate back and forward in history. On pre VS2015 this did not necessarily work with a non-us keyboard layout.

ctr-esc – Close the active tool window.

ctrl-shift-f12 – Go to the next item in a list, typically compile error but some other lists work too. Try compile with some errors. Then you can step through the errors with this shortcut.
TODO:Check it really is shift-alt-f12 as my muscle memory seems to elude me.

ctrl-shift-l – Delete current row. This is not as good as can be. Ctrl-l should be shorter but it is bound to cutting the row. Unnecessary really since ctrl-x does this if nothing is marked. I have earlier bound deleting a row to ctrl-l but nowadays don’t bother; i press ctrl-shift instead.

ctrl-x and ctrl-c – When nothing is marked they cut respectively copy the current row.

ctrl-shift-v – Cycle through Visual studio’s multi clipboard. A multi clipboard is a must. I use Ditto instead so I get a system wide multi clipboard with search capability and power off persistance.

shift-alt-enter – Maximises the window even more. There is no need for the top bar which says “Your project name – Microsoft Visual studio” and takes up the whole top of the screen. In the VB6 IDE one could even get rid of the menu; it is seldom needed to be visible – one just pressed alt or moved the mouse to the top and it showed again.

ctrl-r-t – Run the test method the caret is positioned in. If the caret is outside of a method is runs the whole class. If it is outside the class… – I haven’t checked, you tell me. Both Visual studio and resharper lacks some basic functionality like debug last method; as it stands now there is only run last method. I have the need to switch back and forth between running and debugging. If you are deep into writing tests – check Ncrunch which does a fantastic job of running tests and visualising what is tested and what is not. It also has the handy tool run any test that brings me to where the caret presently is. (r#)

ctrl-r-ctrl-t – Debug the test method… see ctrl-r-t. (r#)

One can have two windows side by side. Tests on the left and testee on the right. Or HTML on the left and Javascript on the right. Or client code on the left and server code on the right. One can have three windows side by side. Four.