This post will walk you through, how I have built my first Docker container.

Prepare the environment

If you already have Windows 10 or Windows server 2016 machine. Download code to configure Docker environment.

If you would like to have a new VM Get the code from here. This will create Windows server 2016 VM with Docker, VS Code, git and chrome.

Let’s discuss some basic docker commands, before we start

Let’s create our first windows container

To start with VS Code, Install Docker extension. In addition to this you can also install the PowerShell, Azure Resource Manager Tools extensions.

Docker Extension in VS Code

Lab 1 - Objective

  • Step 1: Create docker file and use default IIS server image from docker hub.
  • Step 2: Build container
  • Step 3: Run container

let’s run some basic command

docker images

docker ps

docker ps -a

Step 1: Dockerfile

  • Create a folder - Demo
  • Open this folder in VS Code
  • Create a file without extension (file name - dockerfile) and save it.

Docker Extension in VS Code

FROM microsoft/iis

LABEL Author="Ajeet Chouksey"
LABEL Image="IIS"

EXPOSE 80

CMD ["ping localhost -t"]

FROM

The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction.

Refer Docker HUB, and search for available images.

LABEL

The LABEL instruction adds metadata to an image. A LABEL is a key-value pair. To include spaces within a LABEL value, use quotes and backslashes as you would in command-line parsing. An image can have more than one label. You can specify multiple labels on a single line.

LABEL Author="Ajeet Chouksey"
LABEL Image="IIS"

or

LABEL Author="Ajeet Chouksey" \
Image="IIS"

EXPOSE

The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified.

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.

CMD

The main purpose of a CMD is to provide defaults for an executing container.

docker build -t <<name>> .

Step 2: BUILD

The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.

Docker Build

Docker Build

DockerImages

Docker PS

Step 3: RUN

docker run -d demo <<>>

Docker run -d

Let’s run the following command

docker run -it -p 80:80 demo
docker run -it -p 80:80 demo powershell

in next post, we will build and run the container and try to customize IIS site. We will also use the Azure Container Registry and Azure Container Instance to host and run the container.


Please do let me know your thoughts/ suggestions/ question in disqus section.


Related Posts

About Ajeet Chouksey

With a robust background spanning more than 18 years, I am an adept Azure and Azure DevOps architect and engineer, dedicated to crafting Azure-centric solutions that prioritize customer requirements and agile methodologies. My expertise encompasses steering extensive cloud migration initiatives and advocating for Azure best practices, all aimed at streamlining costs and steering multinational teams towards success. Fueled by a passion for technological innovation, I am committed to perpetual learning, constantly advancing my proficiency in Azure, AI, MLOps, and Product Management to stay at the forefront of the industry..