Windows container

Running Windows Container in Windows 2016

In this blog, we will show you how to running windows container in windows 2016 using docker commands.

OVERVIEW

We are using the docker client command docker.exe to run the windows containers in windows 2016. There are many options available in docker command. you can use the help page to find different options about this command.

RUN WINDOWS CONTAINER IN AN INTERACTIVE MODE

  •  To run a container in an interactive mode, use the below command.

docker run -it microsoft/nanoserver cmd

In the above example,

docker – Command name

run – sub option of to run the container

-it – To run the container in interactive mode

microsoft/nanoserver – Image name for this container

cmd – To execute the cmd.exe process for interactive experience

windows container

“Note: By default, docker will use the latest images if you are not provide the tag name for the image.

Also, we can provide tag along with the image name as shown below.

docker run –it microsoft/nanoserver:latest cmd

Once docker started successfully it shows the command prompt.

windows container
  • To stop the container, type exit and press enter.

DISCONNECT THE CONTAINER

  • To keep the container in the running mode, press CTRL key+PQ
  • Once you press these keys it will disconnect from the container.
windows container
  • To list the docker process, type the below command.

docker ps

windows container

STOP THE CONTAINER

  •  To stop the container, type below command.

Syntax : docker stop <container ID> or <container name>

Example : docker stop 03

Note : We can use the first two character of container ID for short form.

image
  • There are no running containers available now.
image
  • To show all the containers including stopped, type the below command.

docker ps –a

image

START THE CONTAINER

  • To start the container, type the below command.

Syntax : docker start <container ID> or <container name>

Example : docker start 03

image
image

SETTING NAME FOR CONTAINER

  • By default,  Microsoft will choose a random name for a container. To set a name while creating the container, type the below command.
image
  • Once the container created successfully, press CTRL+PQ to disconnect from the container. Then type docker ps command to list the container(s).
image
  • So we can use the name srv01 to stop, start and delete the containers.
image

DELETE A CONTAINER

  • To delete a container, type the below command.

Syntax : docker rm <container ID> or <container name>

Example : docker rm srv01

image
  • If you try to delete the running container using rm command it shows the below error.
image
  • To delete the running container, type the below command.

Syntax : docker rm –f <container ID> or <container name>

Example : docker rm -f 03

image

RUNNING IN DETACH MODE WHILE CREATING THE CONTAINER

  • To run in the detach mode while creating the container, type the below command.

Syntax : docker run –d <container image> <process command>

Example : docker run –d microsoft/nanoserver ping 127.0.0.1 –t

image
  • When we list the docker process, we can able to see the container running in background.
image
  • To start another process inside a running container, type the below command.

Syntax: docker exec -it <container ID>  or <container name> <process command>

Example: docker exec -it 68 cmd

image
  • After few seconds, it shows the command prompt. Type hostname to verify the container.
image
  • Type exit to exit from the container. Now execute the docker ps command to view the docker process list.
image

The command which we ran during detach mode is still running in the background.

COLLECTING INFORMATION ABOUT CONTAINER

  • To view the information about the container, type the below command.

Syntax: docker inspect <container ID> or <container name>

Example : docker inspect 68

docker inspect

It shows the information about the container in JSON format.

VIDEO

Thanks for reading this blog. We hope it will be useful for you to start, stop & delete a windows container in Windows 2016.

Loges