Docker:: Install Nginx Webserver on top of Windows 10 Home

×

Overview

Overview Docker Implementations for Windows

  • Docker for Windows requires Hyper-V for Virtualization
  • Docker for Windows runs on Microsoft Windows 10 Professional or Enterprise 64-bit
  • For previous versions like Windows 7 or for Windows 10 HOME you need to use Docker Toolbox.
  • Docker Toolbox uses VirtualBox for Virtualization. Note Hyper-V Virtualization should be disabled.

Overview Docker ToolBox

  • Docker Toolbox use VirtualBox for Virtualization
  • Docker-machine creates a VM to host the Docker engine and assigns two interfaces to the machine.
  • Host-only interface, which lets the local Docker process communicate with the Docker daemon running inside the VM.
  • NAT interface, which allows the Docker containers to make outgoing connections to your local LAN and the Internet.

Versions Used

Component Version
OS Windows10 Home
Docker v18.09.0
VirtualBox VirtualBox 5.2.8r

Note: In following we will use Docker ToolBox !

Installation and Setup Docker Machine

  • Download & Install Docker ToolBox
  • Click on Docker Quick-Start Terminal

Printout from Docker Quickstart Terminal

Running pre-create checks...
(default) Unable to get the local Boot2Docker ISO version:  Did not find prefix "-v" in version string
(default) Default Boot2Docker ISO is out-of-date, downloading the latest release...
(default) Latest release for github.com/boot2docker/boot2docker is v18.09.0
(default) Downloading C:\Users\helmut\.docker\machine\cache\boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.09.0/boot2docker.iso...
(default) 0%....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
...
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: C:\Program Files\Docker Toolbox\docker-machine.exe env default


                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/

docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com

Verfiy the Docker settings

C:\Users\helmut>docker-machine env default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\helmut\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
SET COMPOSE_CONVERT_WINDOWS_PATHS=true
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

Validate setup by using docker-machine command

A default Docker machine was created by above setup
C:\Users\helmut> docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.0

Verify the IP Adreess
C:\Users\helmut> docker-machine ip
192.168.99.100

Login into dogger-machine 
C:\Users\helmut> docker-machine ssh
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

What drives are currently mounted ?
docker@default:~$ mount |  grep vbox
/c/Users on /c/Users type vboxsf (rw,nodev,relatime)

Verify the network Setup
docker@default:~$ ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:C9:C1:18:F8
          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr 08:00:27:2D:22:35
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe2d:2235/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1288 errors:0 dropped:0 overruns:0 frame:0
          TX packets:927 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:170783 (166.7 KiB)  TX bytes:179331 (175.1 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:84:00:6E
          inet addr:192.168.99.100  Bcast:192.168.99.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe84:6e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:45 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:10419 (10.1 KiB)  TX bytes:10880 (10.6 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Validate the Docker Installation by creating and running the Docker Hello World Container


C:\Users\helmut> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Status: Downloaded newer image for hello-world:latest

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.
    (amd64)
 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.

Run and verify a basic Nginx Installation

Install Nginx Webserver in a new Container

C:\Users\helmut>  docker run -d -p 80:80 --name webserver nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
177e7ef0df69: Pull complete
ea57c53235df: Pull complete
bbdb1fbd4a86: Pull complete
Digest: sha256:b543f6d0983fbc25b9874e22f4fe257a567111da96fd1d8f1b44315f1236398c
Status: Downloaded newer image for nginx:latest
7d12192427fbb4466b72c4cb0044699d37e76263ac9d86b77d939419ee9aca36

C:\Users\helmut> docker-machine ip
192.168.99.100

Run an HTTP request using curl
C:\Users\helmut>  curl http://192.168.99.100/

<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>


Check Webserver Logs 
C:\Users\helmut>  docker  logs webserver
192.168.99.1 - - [30/Dec/2018:15:13:01 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"

Verify docker-machine and docker comtainer status 
C:\Users\helmut> docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.0

C:\Users\helmut> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
7d12192427fb        nginx               "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes        0.0.0.0:80->80/tcp   webserver

Create a NEW Virtualbox Common Folder so we can easily copy HTML files to our Container

Setup a Common Folder within VirtualBox
dockerInstall_img3.jpg NOT Found
After Common Folder was created in VirtualBox restart docker-machine 
C:\Users\helmut> docker-machine stop
Stopping "default"...
Machine "default" was stopped.

C:\Users\helmut> docker-machine start
Starting "default"...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

Login to our docker-machine and validate mount status 
C:\Users\helmut> docker-machine ssh
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@default:~$ mount | grep vbox
/d/docker on /d/docker type vboxsf (rw,nodev,relatime)
/c/Users on /c/Users type vboxsf (rw,nodev,relatime)

Recreate the Webserver and mount a Volume for data Exchange

Validate Comtainers 
C:\Users\helmut> docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS                NAMES
78beb40c2cf1        nginx               "nginx -g 'daemon of…"   8 seconds ago       Up 8 seconds             0.0.0.0:80->80/tcp   webserver
20736855e599        hello-world         "/hello"                 2 hours ago         Exited (0) 2 hours ago                        elated_dewdney

Drop Comtainer 
C:\Users\helmut> docker stop webserver
webserver

C:\Users\helmut> docker rm webserver
webserver

Recreate Containe and mount a volume 
C:\Users\helmut> docker run  -d -p 80:80 -v /d/docker/nginx:/usr/share/nginx/html --name webserver nginx
e21b8891b5d338e9baa4a3a23b7c387535561aa61af308e6c4b29efda28262f8

Copy a HTML File to the Windows Directory 
C:\Users\helmut> cat d:\docker\nginx\t1.html

Hallo Helmut

Use curl to validate our setup C:\Users\helmut> curl http://192.168.99.100/t1.html

Hallo Helmut

Reference

Enable docker-machine for DHCP networking

  • For testing multipe docker images the docker-machine may need to get an IP Address from Your DHCP server
  • To achieve this open VirtualBox Manager and create a 3.rd Briged Network Adapater
Setup a brigde Network Apdapter with VirtualBox Manager
dockerInstall_img4.jpg NOT Found

Reboot your docker-machine and validate your Network settings

D:\dev\myprojects\dobby-the-companion>  docker-machine ssh
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net


docker@default:~$ ifconfig
docker0   Link encap:Ethernet  HWaddr 02:42:2E:E3:AF:56
          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0
          inet6 addr: fe80::42:2eff:fee3:af56/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:32 errors:0 dropped:0 overruns:0 frame:0
          TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2580 (2.5 KiB)  TX bytes:4752 (4.6 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:2D:22:35
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe2d:2235/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:523 errors:0 dropped:0 overruns:0 frame:0
          TX packets:529 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:47019 (45.9 KiB)  TX bytes:54701 (53.4 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:84:00:6E
          inet addr:192.168.99.100  Bcast:192.168.99.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe84:6e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:417 errors:0 dropped:0 overruns:0 frame:0
          TX packets:409 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:97354 (95.0 KiB)  TX bytes:80937 (79.0 KiB)

eth2      Link encap:Ethernet  HWaddr 08:00:27:4F:93:12
          inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe4f:9312/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6190 errors:0 dropped:0 overruns:0 frame:0
          TX packets:884 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:448925 (438.4 KiB)  TX bytes:60435 (59.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Recreate and test your docker Image

  • Nginx Webserver should not listen to 2 IPs including a DHCP address
D:\dev\myprojects\dobby-the-companion> docker stop webserver
webserver
D:\dev\myprojects\dobby-the-companion> docker rm webserver
webserver

D:\dev\myprojects\dobby-the-companion> docker run  -d -p 80:80 -v /d/docker/nginx:/usr/share/nginx/html --name webserver nginx
534cc7f20d868978d90a2762c25a39dba05628bcb8fdd29f1fd14022a4c7c3ba


Validate our Nginx Webserver - should now listening on both IPs 
D:\dev\myprojects\dobby-the-companion> curl http://192.168.1.5/t1.html

Hallo Helmut

D:\dev\myprojects\dobby-the-companion> curl http://192.168.99.100/t1.html

Hallo Helmut

Reference

Usefull Comannds

Recreate Certificates

C:\Users\helmut> docker-machine regenerate-certs
Regenerate TLS machine certs?  Warning: this is irreversible. (y/n): y
Regenerating TLS certificates
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...

Login into a Docker Container and run a Linux Command

C:\Users\helmut> docker exec -it webserver /bin/bash
root@9d1edf9c3952:/# uname -a
Linux 9d1edf9c3952 4.14.79-boot2docker #1 SMP Thu Nov 8 01:56:42 UTC 2018 x86_64 GNU/Linux

Login into a Docker Container and install add. packages

C:\Users\helmut> docker exec -it webserver /bin/bash
root@438da12bf45f:/# apt-get update
root@438da12bf45f:/# apt-get install iputils-ping

Potential Errors

C:\WINDOWS\system32> docker-machine restart
Restarting "default"...
Starting "default"...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
Error setting up host only network on machine start: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe modifyvm default --nic2 hostonly --nictype2 82540EM --nicpromisc2 deny --hostonlyadapter2 VirtualBox Host-Only Ethernet Adapter #3 --cableconnected2 on failed:
VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended info not available)
VBoxManage.exe: error: Context: "LockMachine(a->session, LockType_Write)" at line 525 of file VBoxManageModifyVM.cpp

-->Fix: Use Windows Taks Manager and kill all VBoxXXXXX processes