today I want to write a few words about usage of docker for windows.
First of all, I want to point what is docker at all. There are many ideas of how to explain it, but in my opinion docker is like installed and configured piece of software with needed fragment of operating system. It can be installed software with windows or with Linux fragment. What is also interesting is that Windows 10 with docker for windows knows how to execute Linux docker containers. So it means that from inside of windows you can have nginx Linux server.
As you can see from my screenshot, docker for windows installed MobyLinuxVM and if there is a need to execute docker contaner for Linux, it will use image from Hyper-V manager in order to execute docker app from that space.
Some commands of docker
I suppose that most usefull command of working with docker will be or could be docker ps. ps comes from Linux world and stands for process status.
Initially it will have following output:
PS C:\Windows\system32> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Let's start with simplest possible hello world docker container:
docker run hello-world
If you run this command for the first time, the docker will make initial download of simplest image and execute for you it. If you run it for the second time you'll see following output:
PS C:\Windows\system32> docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
For more examples and ideas, visit:
this output is intended to prove to you that docker with it's internals was installed successfully.
Now let me introduce me docker ps -a
at my machine this command gives following output:
PS C:\Windows\system32> docker ps -a
as you can see from the picture I have plenty of images, with status Exited ....
If you want to see working images ( or containers that you can start ) use docker images
"Install" with docker
with next command that I want to introduce is download something more complicated. For example rabbitmq image:
as you can see from the picture in order to get rabbitmq downloaded and executed I just run docker run rabbitmq.
In order to terminate container following can be used:
docker stop some identifier. I prefer to use container id or fragment of it. Like this:
docker stop a30eaa297fa
Run IIS nanoserver
Lets suppose that for some reason you need to run IIS.
For this purpose you can use the following command:
docker run -p 81:80 -d --name iis microsoft/iis:nanoserver
it will have the following meaning:
run latest microsoft nanoserver with mapping from port 80 of nanoserver to port 81 to external world.
-d will have following meaning: fire and forget or detached container.
As opposite to -d can be considered -it or interactive terminal.
--name allows to give to it some name which can simplify finding of needed instance.
Download without executing
One more command is usefull:
docker pull microsoft/windowsservercore
this command will download image of windowsservercore without executing it.
Get to installed IIS
If you executed docker run -p 81:80 -d --name iis microsoft/iis:nanoserver and expect that you'll be able to open in localhost your instance of IIS, prepare to be disappointed. There is a bug in Windows docker container, which will require from you additional steps.
- Execute docker inspect iis
- In the networks section you'll find Networks, which will provide you needed IP address:
3. Type that address without ( !!! ) mapping to port 81, and you'll see IIS welcome screen.
Take a look at screenshot below, and tell me which command was executed via docker:
Most probably you'll tell C:\ServiceMonitor... What stands instead of ...?
In order to discover it, you can use key --no-trunc. Compare with screenshot below:
with this command you can see, that following command was executed: C:\ServiceMonitor.exe w3svc.