Docker Windows10

2/12/2022by admin

Windows Server 2016 is the where Docker Windows containers should be deployed for production. For developers planning to do lots of Docker Windows container development, it may also be worth setting up a Windows Server 2016 dev system (in a VM, for example), at least until Windows 10 and Docker for Windows support for Windows containers matures. Install Docker Desktop for Windows. Run the Docker Desktop Installer executable. Let the checkboxes activated. Two minutes later. Start Docker and verify the Availability Windows 10 Run Docker Container. After starting the Docker Desktop, you get a notification that Docker is starting. Docker is recognising that WSL is installed. Docker for Windows is a product offered by Docker that allows users to set up a Docker container on a client-based operating system (Windows 10). Containers are all the rage these days, and Docker is king of the containers.

-->

This tutorial shows how to run an ASP.NET Core app in Docker containers.

In this tutorial, you:

  • Learn about ASP.NET Core Docker images
  • Download an ASP.NET Core sample app
  • Run the sample app locally
  • Run the sample app in Linux containers
  • Run the sample app in Windows containers
  • Build and deploy manually

ASP.NET Core Docker images

For this tutorial, you download an ASP.NET Core sample app and run it in Docker containers. The sample works with both Linux and Windows containers.

The sample Dockerfile uses the Docker multi-stage build feature to build and run in different containers. The build and run containers are created from images that are provided in Docker Hub by Microsoft:

  • dotnet/sdk

    The sample uses this image for building the app. The image contains the .NET SDK, which includes the Command Line Tools (CLI). The image is optimized for local development, debugging, and unit testing. The tools installed for development and compilation make the image relatively large.

  • dotnet/core/sdk

    The sample uses this image for building the app. The image contains the .NET Core SDK, which includes the Command Line Tools (CLI). The image is optimized for local development, debugging, and unit testing. The tools installed for development and compilation make the image relatively large.

  • dotnet/aspnet

    The sample uses this image for running the app. The image contains the ASP.NET Core runtime and libraries and is optimized for running apps in production. Designed for speed of deployment and app startup, the image is relatively small, so network performance from Docker Registry to Docker host is optimized. Only the binaries and content needed to run an app are copied to the container. The contents are ready to run, enabling the fastest time from docker run to app startup. Dynamic code compilation isn't needed in the Docker model.

  • dotnet/core/aspnet

    The sample uses this image for running the app. The image contains the ASP.NET Core runtime and libraries and is optimized for running apps in production. Designed for speed of deployment and app startup, the image is relatively small, so network performance from Docker Registry to Docker host is optimized. Only the binaries and content needed to run an app are copied to the container. The contents are ready to run, enabling the fastest time from docker run to app startup. Dynamic code compilation isn't needed in the Docker model.

Prerequisites

  • Docker client 18.03 or later

    • Linux distributions

Download the sample app

  • Download the sample by cloning the .NET Docker repository:

Run the app locally

  • Navigate to the project folder at dotnet-docker/samples/aspnetapp/aspnetapp.

  • Run the following command to build and run the app locally:

  • Go to http://localhost:5000 in a browser to test the app.

  • Press Ctrl+C at the command prompt to stop the app.

Run in a Linux container

Docker Windows10

  • In the Docker client, switch to Linux containers.

  • Navigate to the Dockerfile folder at dotnet-docker/samples/aspnetapp.

  • Run the following commands to build and run the sample in Docker:

    The build command arguments:

    • Name the image aspnetapp.
    • Look for the Dockerfile in the current folder (the period at the end).

    The run command arguments:

    • Allocate a pseudo-TTY and keep it open even if not attached. (Same effect as --interactive --tty.)
    • Automatically remove the container when it exits.
    • Map port 5000 on the local machine to port 80 in the container.
    • Name the container aspnetcore_sample.
    • Specify the aspnetapp image.
  • Go to http://localhost:5000 in a browser to test the app.

Windows10

Run in a Windows container

  • In the Docker client, switch to Windows containers.
Docker windows10 install

Navigate to the docker file folder at dotnet-docker/samples/aspnetapp.

  • Run the following commands to build and run the sample in Docker:

  • For Windows containers, you need the IP address of the container (browsing to http://localhost:5000 won't work):

    • Open up another command prompt.

    • Run docker ps to see the running containers. Verify that the 'aspnetcore_sample' container is there.

    • Run docker exec aspnetcore_sample ipconfig to display the IP address of the container. The output from the command looks like this example:

  • Copy the container IPv4 address (for example, 172.29.245.43) and paste into the browser address bar to test the app.

Build and deploy manually

In some scenarios, you might want to deploy an app to a container by copying its assets that are needed at run time. This section shows how to deploy manually.

Docker Windows10 Install

  • Navigate to the project folder at dotnet-docker/samples/aspnetapp/aspnetapp.

  • Run the dotnet publish command:

    The command arguments:

    • Build the app in release mode (the default is debug mode).
    • Create the assets in the published folder.
  • Run the app.

    • Windows:

    • Linux:

  • Browse to http://localhost:5000 to see the home page.

To use the manually published app within a Docker container, create a new Dockerfile and use the docker build . command to build an image.

To see the new image use the docker images command.

The Dockerfile

Here's the Dockerfile used by the docker build command you ran earlier. It uses dotnet publish the same way you did in this section to build and deploy.

In the preceding Dockerfile, the *.csproj files are copied and restored as distinct layers. When the docker build command builds an image, it uses a built-in cache. If the *.csproj files haven't changed since the docker build command last ran, the dotnet restore command doesn't need to run again. Instead, the built-in cache for the corresponding dotnet restore layer is reused. For more information, see Best practices for writing Dockerfiles.

The Dockerfile

Here's the Dockerfile used by the docker build command you ran earlier. It uses dotnet publish the same way you did in this section to build and deploy.

As noted in the preceding Dockerfile, the *.csproj files are copied and restored as distinct layers. When the docker build command builds an image, it uses a built-in cache. If the *.csproj files haven't changed since the docker build command last ran, the dotnet restore command doesn't need to run again. Instead, the built-in cache for the corresponding dotnet restore layer is reused. For more information, see Best practices for writing Dockerfiles.

The Dockerfile

Here's the Dockerfile used by the docker build command you ran earlier. It uses dotnet publish the same way you did in this section to build and deploy.

Additional resources

  • ASP.NET Core Docker sample (The one used in this tutorial.)

Next steps

The Git repository that contains the sample app also includes documentation. For an overview of the resources available in the repository, see the README file. In particular, learn how to implement HTTPS:

Have you previously installed Docker Toolbox, Docker Machine, or VirtualBox?

Docker for Windows now requires Microsoft’s Hyper-V. Once enabled, VirtualBox will no longer be able to run virtual machines (your VM images will still remain). You can still use docker-machine to manage remote hosts.

You have the option to import the default VM after installing Docker for Windows from the Settings menu in the System Tray.

Docker for Windows enables Hyper-V if necessary; this requires a reboot.

Requirements

Docker for Windows runs on 64-bit Windows 10 Pro, Enterprise, and Education; 1511 November update, Build 10586 or later. Docker plans to support more versions of Windows 10 in the future.

Installation

  1. Download Docker.
  2. Double-click InstallDocker.msi to run the installer.
  3. Follow the Install Wizard: accept the license, authorize the installer, and proceed with the install.
  4. Click Finish to launch Docker.
  5. Docker starts automatically.
  6. Docker loads a “Welcome” window giving you tips and access to the Docker documentation.

That’s it!

Verification

The whale in the status bar indicates a running (and accessible via terminal) Docker instance.

Open PowerShell or your favorite Windows terminal (e.g., Command prompt) and enter docker run hello-world.

Windows prompts you for access every time Docker starts, allowing Docker to manage the Hyper-V VM’s. The first time Docker starts, you may need to provide the token from the Beta invitation email. When initialization completes, select About Docker from the notification area and verify you have the latest version.

From PowerShell (or your favorite Windows terminal), check the versions of docker, docker-compose, and verify your installation:

Before you stop, let’s test a Dockerized webserver; from PowerShell or cmd.exe, run:

If your host does not already have it, Docker downloads nginx from Docker Hub and starts it. As soon as the download completes, point your web browser to http://docker to view the start page. You should see:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.Commercial support is available at nginx.com.

Thank you for using nginx.

Common Pitfalls

Docker Windows 10 Install

CPU

Docker Windows 10 Image

If your CPU does not support virtualization, or if you do not have a 64-bit CPU, you cannot run Docker locally.

Docker

Operating System

If you do not run a 64-bit version of Windows Windows 10 Pro, Enterprise, or Education; 1511 November update, Build 10586 or later, you cannot run Docker for Windows.

You can install Docker Toolbox if you have a 64-bit version of Windows 7 or later. Alternately, you do have the option to upgrade.

Docker Windows 10 Home

Next: Install Docker on Linux
Requirements and things to know before installing Docker for Linux.

Comments are closed.