Nanoserver Archives - TEKSpace Blog https://blog.tekspace.io/tag/nanoserver/ Tech tutorials for Linux, Kubernetes, PowerShell, and Azure Wed, 30 Aug 2023 15:20:21 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://blog.tekspace.io/wp-content/uploads/2023/09/cropped-Tekspace-logo-icon-32x32.png Nanoserver Archives - TEKSpace Blog https://blog.tekspace.io/tag/nanoserver/ 32 32 Building your first docker image for Windows https://blog.tekspace.io/how-to-create-docker-image-for-windows-containers/ https://blog.tekspace.io/how-to-create-docker-image-for-windows-containers/#respond Sat, 30 Mar 2019 01:37:45 +0000 https://blog.tekspace.io/index.php/2019/03/30/how-to-create-docker-image-for-windows-containers/ In this tutorial, I will demonstrate how to host an ASP.NET Core 2.2 application on Windows Containers by using a Docker image. A Docker image will be packaged with an ASP.NET Core application that will be run when a container is spun up.Before we get started with creating a Docker image. Let’s make sure we

The post Building your first docker image for Windows appeared first on TEKSpace Blog.

]]>
In this tutorial, I will demonstrate how to host an ASP.NET Core 2.2 application on Windows Containers by using a Docker image. A Docker image will be packaged with an ASP.NET Core application that will be run when a container is spun up.
Before we get started with creating a Docker image. Let’s make sure we have prerequisites done.

Prerequisites

Once you have the prerequisites, we will use a publicly available ASP.NET Core base image from Microsoft. Microsoft maintains their Docker images on Docker hub. Docker hub is a container registry to manage your Docker images either by exposing the image publicly or maintaining it privately. Private image responsibilities cost money. Visit Docker Hub website to learn more about image repository management.

Building your first Docker Image

Step 1: Open the PowerShell console as an administrator

Step 2: Let’s get started by pulling ASP.NET Core 2.2 Docker image from Docker hub by executing the below command.

docker pull mcr.microsoft.com/dotnet/core/aspnet:2.2

Your output should look similar to what is shown below:

Step 3: Create a folder with your preference name whatever you prefer. I will use c:\docker\ for demonstration purposes.

mkdir c:\docker

Step 4: Download ASP.NET Core application package from this URL.

Invoke-WebRequest -UseBasicParsing -OutFile c:\docker\WebAppCore2.2.zip https://github.com/rahilmaknojia/WebAppCore2.2/archive/master.zip

What we are doing in the above command is downloading packaged code that is already built to save time on building a package.

Step 5: Extract WebAppCore2.2.zip by using the PowerShell 5.0 native command. If you do not have PowerShell 5.0 and above, you will have to manually extract the package.

Expand-Archive c:\docker\WebAppCore2.2.zip -DestinationPath c:\docker\ -Force 

Step 6: Now let’s create a Docker file in c:\docker folder.

New-Item -Path C:\docker\Dockerfile -ItemType File

Step 7: Go ahead and open C:\docker folder path in Visual Studio Code.

Step 8: Now we will open Dockerfile by double-clicking on the file in Visual Studio Code to start writing the required steps to build an image.

Copy and paste the code below into Dockerfile.

# Pull base image from Docker hub 
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

# Create working directory
RUN mkdir C:\\app

# Set a working directory
WORKDIR c:\\app

# Copy package from your machine to the image. Also known as staging a package
COPY WebAppCore2.2-master/Package/* c:/app/

# Run the application
ENTRYPOINT ["dotnet", "WebAppCore2.2.dll"]

What we told the Dockerfile is to pull an asp.net core base image from Docker hub. Then we ran a command to create a directory called app in c:\app path. We also told the container to set c:\app as a working directory. That way we can access binary directly when the container is spun up. We also added a step to copy all the binaries from c:\docker\WebAppCore2.2-master\Package\ to destination path in container c:\app. Once we had the package staged in the container, we told it to run the application by executing dotnet WebAppCore2.2.dll so that the app would be accessible from outside the container. To learn more about Dockerfile for Windows, check out this Microsoft documentation.

Now that you have the required steps to build an image, let’s go ahead with the below steps.

Step 9: Navigate to Dockerfile working directory from PowerShell console. If you are already in that path, you can ignore it.

cd c:\docker

Step 10: Execute the below command to build a container image.

docker build -t demo/webappcore:2.2.0

The above command will create a Docker image under demo path. With the image name called as webappcore and version 2.2.0.

Your output should look like below once it is successful:

PS C:\docker> docker build -t demo/webappcore:2.2.0 .
Sending build context to Docker daemon  9.853MB
Step 1/5 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
 ---> 36e5a01ef28f
Step 2/5 : RUN mkdir C:\\app
 ---> Using cache
 ---> 8f88e30dcdd0
Step 3/5 : WORKDIR c:\\app
 ---> Using cache
 ---> 829e48e68bda
Step 4/5 : COPY WebAppCore2.2-master/Package/* c:/app/
 ---> Using cache
 ---> 6bfd9ae4b731
Step 5/5 : ENTRYPOINT ["dotnet", "WebAppCore2.2.dll"]
 ---> Running in 4b5488d5ea5f
Removing intermediate container 4b5488d5ea5f
 ---> 9729270fe1ac
Successfully built 9729270fe1ac
Successfully tagged demo/webappcore:2.2.0

Step 11: Once the image has been built, you are now ready to run the container. Execute the below command.

docker run --name webappcore --rm -it -p 8000:80 demo/webappcore:2.2.0

The above command will create a new container called webappcore with parameters.

  • --rm is used to automatically remove the container after it is shutdown.
  • -it will open a session into your container and output all the logs.
  • -p is used for creating an external port and assigning it to the internal port of a container. Port 8000 is exposed to outside containers, and port 80 is used to access the app within the container.
  • demo/webappcore:2.2.0 is the path to the Docker image to run as a container.

Output of a running container

Step 12: Browsing your application from your local machine localhost:8000.

This is it! You ran your first Docker container in your local environment. Thank you for following the tutorial. Please comment below for any issue or feedback you would like to share.

The post Building your first docker image for Windows appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/how-to-create-docker-image-for-windows-containers/feed/ 0
Run your first Windows Container on your Windows 10 https://blog.tekspace.io/run-your-first-windows-container-on-your-windows-10/ https://blog.tekspace.io/run-your-first-windows-container-on-your-windows-10/#respond Sun, 24 Mar 2019 15:59:32 +0000 https://blog.tekspace.io/index.php/2019/03/24/run-your-first-windows-container-on-your-windows-10/ Windows 10 now comes with container features available to pro and enterprise versions. To get started with containers on Windows 10, please make sure the below prerequisites are met. Pre-requisites Let’s ensure we have prerequisites installed before we get started with docker cli and container installation. If you already have the below items installed, you

The post Run your first Windows Container on your Windows 10 appeared first on TEKSpace Blog.

]]>
Windows 10 now comes with container features available to pro and enterprise versions. To get started with containers on Windows 10, please make sure the below prerequisites are met.

Pre-requisites

Let’s ensure we have prerequisites installed before we get started with docker cli and container installation. If you already have the below items installed, you can skip them and proceed with the setup.

Windows 10 now comes with container feature available for developers and devops engineers to start using Docker containers in their local environment. To enable containers for Windows 10, execute the below command.

Enable-WindowsOptionalFeature -FeatureName containers -Online -all

NOTE: Upon installation, you will be prompted to reboot your system after the container feature is enabled. It is recommended that you select yes to reboot your system.

Install Docker CLI

Now we will go ahead and download latest docker cli by using the Chocolate package management tool.

Once you have choco installed, go ahead and open PowerShell as an administrator and execute the below command.

choco install docker

You will be asked to say yes or no. Go ahead and continue with the interactive installation process by pressing Y. The output should look like below if the installation was successful.

Now that you have docker cli installed, you are now ready to run your first Docker container.

Installing Docker Enterprise Edition (EE)

To install Docker EE on Windows 10, please make sure above setup is successfully completed. To get started, go ahead and execute the below commands from an elevated PowerShell console.

To go to the Downloads’ folder of your current user.

cd ~\Downloads

Download Docker Enterprise Edition from online

Invoke-WebRequest -UseBasicParsing -OutFile docker-18.09.3.zip https://download.docker.com/components/engine/windows-server/18.09/docker-18.09.3.zip

NOTE: In this tutorial I am using Docker 18.09.3 version. This may change in the future. You can follow the updated document from here.

Unzip the Docker package.

Expand-Archive docker-18.09.3.zip -DestinationPath $Env:ProgramFiles -Force

Execute the below script to set up and start Docker.

# Add Docker to the path for the current session.
$env:path += ";$env:ProgramFiles\docker"

# Optionally, modify PATH to persist across sessions.
$newPath = "$env:ProgramFiles\docker;" +
[Environment]::GetEnvironmentVariable("PATH",
[EnvironmentVariableTarget]::Machine)

[Environment]::SetEnvironmentVariable("PATH", $newPath,
[EnvironmentVariableTarget]::Machine)

# Register the Docker daemon as a service.
dockerd --register-service

# Start the Docker service.
Start-Service docker

Test your Docker setup by executing the below command.

docker container run hello-world:nanoserver

Running your first Docker container

In this example, I will be using nanoserver image from Docker hub to run an IIS application.

Step 1: Let’s first check if we have any Docker images pulled from Docker hub. Based on the above setup for Docker, you should have a hello-world Docker image pulled from Docker hub.

docker images

Step 2: Let’s pull a new Docker image from Docker hub to run nanoserver with IIS configured.

docker pull nanoserver/iis

Your final output should look like below.

docker-iis-nanoserver-for-windows-container

Step 3: After we have pulled the latest image from Docker hub, let’s run our first windows container by executing the below command.

docker run --name nanoiis -d -it -p 80:80 nanoserver/iis

After it will return a container ID that you can use to check container status, configuration, etc.

Step 4: Check our first container status by executing the below command.

docker ps -a -f status=running

Status output:

docker-iis-nanoserver-for-windows-container-status

Step 5: Now let’s get the IP address of our container to access it from the browser.

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" nanoiis

Step 6: Copy the IP address that was returned to the PowerShell console and browse it in Internet Explorer.

In my case, I received 172.19.231.54. Yours may be different.

This is it! You have run your first Windows container on your Windows 10 machine. Thank you for following this tutorial.

The post Run your first Windows Container on your Windows 10 appeared first on TEKSpace Blog.

]]>
https://blog.tekspace.io/run-your-first-windows-container-on-your-windows-10/feed/ 0