Figure 10.6 Container layers
A container can be created easily and used in an interactive fashion. In the first
example, I will create a new container based on the windowsservercore base OS image,
run it interactively, and tell it to run cmd.exe. I am not specifying a network, which
means that it will connect to the default NAT network:
docker run -it --name demo1 microsoft/windowsservercore cmd.exe
To run the container as a Hyper-V container, the only change is to add --
isolation=hyperv:
docker run -it --isolation=hyperv --name demo1 microsoft/windowsservercore
cmd.exe
Once the container instance is created, it will open cmd.exe, which is now running
inside the container. The -it switch used with docker run tells Docker to run the
container interactively (-i) with a pseudo text-terminal (-t).
Commands can be entered inside the cmd.exe window—for example, ipconfig. To exit,
simply type exit. The container will change to a stopped state because it was started in
an interactive mode. To view container processes, use docker ps -a:
C:>docker ps ‐a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
9f5c5054438e microsoft/windowsservercore "cmd.exe" 3
minutes ago Exited (0) 2 seconds ago demo1
To restart the container and attach again, use the following:
docker start demo1
docker attach demo1
To delete a container, use the following: