Creating Dockerfiles to be built with Docker for Windows Community Edition.

Creating a Dockerfile is remarkably easy. A Dockerfile is basically a text file, that is used with Docker to build a container from a Docker image.  You usually start by creating a text file named Dockerfile in a new directory. You don’t want to put a Dockerfile in the root of the C drive for example, because every file and folder below the Dockerfile will get packaged into the built container.

First line of a Dockerfile usually is just a comment starting with a pound # sign.

Then you tell Docker what image to use when creating the container like this:

FROM ubuntu:15.04

Next you add a MAINTAINER which is your name and/or email address

MAINTAINER Name name@email.com

Now we start the next line with a RUN command, that tells the container the first command to run. For example,

RUN apt-get update && /bin/bash

After the RUN command, you can then use EXPOSE 80,443 to open firewall ports 80 and 443,

there are a few different commands we can use here, but the last command will be CMD

This CMD line tells the container what process to run as its main process, and since most containers are supposed to run only one process, (although they can run more than one, best-practice is to only run one process in each container)

CMD commands should be written inside of [] brackets…

CMD [“apache2ctl”, “-D”, “FOREGROUND”]
Final Dockerfile should look like this:

 

# Apache Web Server Dockerfile with apache2-utils and vim
FROM ubuntu:15.04
RUN apt-get update && apt-get install -y \
        apache2 \
        apache2-utils \
        vim \
        && apt-get clean \
        && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 80
CMD [“apache2ctl”, “-D”, “FOREGROUND”]

Setting up Docker on windows server 2016

docker logo

Although Docker is available in Windows Server 2016, it is not immediately obvious how to set it up and start running containers on a Windows Server 2016 server. The first step is to enable the Windows Feature Containers with the PowerShell command Install-WindowsFeature -Name Containers -Verbose . After enabling the Containers feature, installing Docker requires executing the following PowerShell commands:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name DockerMsftProvider -Force
Install-Package -Name docker -ProviderName DockerMsftProvider -Force
Restart-Computer
# Open firewall port 2375
netsh advfirewall firewall add rule name="docker engine" dir=in action=allow protocol=TCP localport=2375

# Configure Docker daemon to listen on both pipe and TCP (replaces docker --register-service invocation above)
Stop-Service docker
dockerd --unregister-service
dockerd -H npipe:// -H 0.0.0.0:2375 --register-service
Start-Service docker

Optionally you can also install the PowerShell Docker Dev module with the following commands:


Register-PSRepository -Name DockerPS-Dev -SourceLocation https://ci.appveyor.com/nuget/docker-powershell-dev

Install-Module Docker -Repository DockerPS-Dev -Scope CurrentUser

To be sure that Docker is installed run the following commands in PowerShell or Command Prompt:
docker version
docker info

Now you can download the microsoft windowsservercore or nanoserver images and begin creating containers.

docker pull microsoft/windowsservercore
docker pull microsoft/nanoserver

Windows Server 2016 – upgrade from tp5 will preserve your files (not supported)

Docker requires windows 10 will not install on windows server 2016

Docker requires windows 10 will not install on windows server 2016

So I am now running Windows Server 2016 on a bunch of physical and virtual servers and have learned that You can upgrade in place from technical preview 5, you will not lose your files. It is not a supported upgrade path, but it works even though the installer says that you will not keep your files, I have installed it over the top of a few virtual machines and no files were deleted in the upgrade. I had a few problems early on, but they were fixed in updates that were installed in the first few days that Windows Server 2016 was available. They had to do with wireless network adapters and some other drivers, but now all of my drivers are installed correctly. I installed the Full server desktop experience version and have been trying to get docker to work, because they said that Docker was integrated with Windows Server 2016, however Docker for Windows only works on Windows 10, it will not install on Windows Server 2016. I remember hearing something about having to run Server Core a few months ago, but I’m not sure if that’s the reason why I can’t get Docker to install on the full server experience. I will be figuring this out as soon as I get some more time. There is one thing that bothers me though, and it is that all of the Windows 10 services are installed on here but Microsoft Edge and the Windows Store is not available, so why have all the extra services that only are necessary for windows store applications. The Downloaded Maps service is unnecessary because there is no Maps app. I would recommend that they either get rid of the extra services that are not needed without having access to Edge and Windows Store apps, or allow the Windows Store apps to be installed since the infrastructure is already in the Server, instead of having all this extra cruft there. I will be installing Server core next, but I hate not being able to get at certain settings that are not available in the server core version.