Fail to pull Windows Core/Nano Server container images with Docker for Windows ‘unknown blob’

During my last session preparation, I switched Docker for Windows to use Windows containers, to be honest I don’t have use it for some times (my nested virtualized Windows Server 2016 do the job) and I had the following error when downloading the microsoft/nanoserver image : unknow blob

image

The issue may be that your Docker for Windows daemon is not completely switch to Windows container. So execute the following line to switch it : & ‘C:\Program Files\Docker\Docker\DockerCli.exe’ –SwitchDaemon

Then pull your image again and things should work :

image

Fail to run a new ASP.NET Core solution with Docker in Visual Studio 2017

Sometimes you want to make a demo to a good friend of you about Docker support in Visual Studio 2017. So your start Visual Studio 2017, create a blank ASP.NET Core (Docker support enabled), press F5 to run the application but things are not really happening like your want. In my case, I had the following message :

The specified framework ‘Microsoft.NETCore.App’, version ‘1.1.2’ was not found.
  – Check application dependencies and target a framework version installed at:
      /usr/share/dotnet/shared/Microsoft.NETCore.App
  – The following versions are installed:
      1.1.1
  – Alternatively, install the framework version ‘1.1.2’.

The issue comes from the fact that Visual Studio 2017 builds a project based on .NET Core 1.1.2 but your Docker image only supports .NET Core 1.1.1 ‘(see message). Why your image doesn’t support 1.1.2 ? Maybe simply because your image is outdated with no support for 1.1.2. So the trick is quite easy and it consists to execute the pull again the image to force Docker to update the base image :

docker pull microsoft/aspnetcore:1.1

This should solve your issue after several minutes of downloading the updated image layer.

Déployer un site ASP.NET Core dans un conteneur Nano Server

Avec l’arrivée de Windows Server 2016, les entreprises se voit maintenant dotées d’un nouveau type de conteneur : les conteneurs Windows (exécutant Windows Server Core et Nano Server). A l’instar des conteneurs Linux, les conteneurs Windows possèdent leurs propres images disponible sur le Docker Hub. L’agnosticité de Docker (peu importe le fournisseur ou la technologie sous-jacente) et les capacités multiplateforme de .NET Core vont nous permettre de migrer une application ASP.NET Core existante s’exécutant dans conteneur Linux (cf dernier post) vers Nano Server sous Windows Server 2016.

Migrer vers un conteneur Windows

Lors du dernier post sur le sujet, nous avions vu comment déployer une application ASP.NET MVC Core dans un conteneur Linux. Voici le Dockerfile (que j’ai nommé Dockerfile.nanoserver permettant d’avoir un Dockerfile par type de conteneur) permettant de déployer la même application dans un conteneur Windows :

[code language= »csharp » highlight= »1″]
FROM microsoft/dotnet:nanoserver
 
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
 
EXPOSE 5000/tcp
ENTRYPOINT ["dotnet", "run", "–server.urls", http://*:5000]
[/code]

Constat : la seule différence à ce fichier Dockerfile est l’image de base (microsoft/dotnet:nanoserver) qui spécifie que nous souhaitons utiliser l’image .NET Core sous Nano Server. C’est aussi simple que ça ! (pour une application .NET Core en tout cas).

En quelques étapes :

  • Exécuter la même commande de Build pour construire votre image : docker build –t <votre tag> –f Dockerfile.nanoserver .

image

  • Démarrer un conteneur avec la commande : docker run –d –p 5000:5000 <votre tag>
  • Ouvrez un navigateur web et naviguez vers votre conteneur : http://<ip de votre conteneur/serveur Windows Server 2016>:5000

Exécuter l’application dans un conteneur Hyper-V

Le conteneur Windows Hyper-V apporte une couche d’isolation et de sécurité supplémentaire à l’application. Le choix entre un conteneur Windows “simple” et un conteneur virtualisé Hyper-V se fera en fonction de vos besoins, ce dernier fournissant une isolation du kernel et une séparation entre le niveau/version des patchs de l’hôte et de l’application.

La ligne de commande est similaire, nous précisons simplement le niveau d’isolement :

  • Démarrer un conteneur avec la commande incluant le paramètres isolation : docker run –d –p 5000:5000 –isolation=hyperv <votre tag>
  • Ouvrez un navigateur web et naviguez vers votre conteneur : http://<ip de votre conteneur/serveur Windows Server 2016>:5000

Container everywhere !

L’introduction des conteneurs Windows avec l’arrivée de Windows Server 2016 annonce une adoption du conteneur encore plus importe que celle actuellement avec les conteneurs Linux : containarization d’applications anciennes ou déploiement d’applications IIS avec le .NET Framework (avec Windows Server Core), déploiement Apps/IIS/AD DS/Hyper-V/etc (avec Nano Server), etc. L’adage Docker “Build, Ship and Run any app, Everywhere” n’a jamais eu autant de sens !