Skip to content

Instantly share code, notes, and snippets.

@oviniciusfeitosa
Created November 16, 2016 23:58
Show Gist options
  • Save oviniciusfeitosa/624f067b98d8a19299f4215fb8a0bfd5 to your computer and use it in GitHub Desktop.
Save oviniciusfeitosa/624f067b98d8a19299f4215fb8a0bfd5 to your computer and use it in GitHub Desktop.
Installing Docker on Windows 10
  1. Install Container Feature

The container feature needs to be enabled before working with Windows containers. To do so run the following command in an elevated PowerShell session.

If you recieve an error saying Enable-WindowsOptionalFeature does not exist, double check that you are running PowerShell as Administrator.

Enable-WindowsOptionalFeature -Online -FeatureName containers -All Because Windows 10 only supports Hyper-V containers, the Hyper-V feature must also be enabled. To enable the Hyper-V feature using PowerShell, run the following command in an elevated PowerShell session.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All When the installation has completed, reboot the computer.

Restart-Computer -Force If you were previously using Hyper-V Containers on Windows 10 with the Technical Preview 5 container base images, be sure to re-enable OpLocks. Please run the following command: Set-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Containers' -Name VSmbDisableOplocks -Type DWord -Value 0 -Force 2. Install Docker

Docker is required in order to work with Windows containers. Docker consists of the Docker Engine, and the Docker client. For this exercise, both will be installed. Run the following commands to do so.

Download the Docker engine and client as a zip archive.

Invoke-WebRequest "https://master.dockerproject.org/windows/amd64/docker-1.13.0-dev.zip" -OutFile "$env:TEMP\docker-1.13.0-dev.zip" -UseBasicParsing Expand the zip archive into Program Files, the archive contents is already in docker directory.

Expand-Archive -Path "$env:TEMP\docker-1.13.0-dev.zip" -DestinationPath $env:ProgramFiles Add the Docker directory to the system path.

For quick use, does not require shell to be restarted.

$env:path += ";c:\program files\docker"

For persistent use, will apply even after a reboot.

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine) To install Docker as a Windows service, run the following.

dockerd --register-service Once installed, the service can be started.

Start-Service Docker 3. Install Base Container Images

Windows containers are deployed from templates or images. Before a container can be deployed, a container base OS image needs to be downloaded. The following commands will download the Nano Server base image.

Pull the Nano Server base image.

docker pull microsoft/nanoserver Once the image is pulled, running docker images will return a list of installed images, in this case the Nano Server image.

docker images

REPOSITORY TAG IMAGE ID CREATED SIZE microsoft/nanoserver latest 105d76d0f40e 4 days ago 652 MB For in depth information on Windows container images see, Managing Container Images.

Please read the Windows Containers OS Image EULA which can be found here – EULA. 4. Deploy Your First Container

For this simple example a ‘Hello World’ container image will be created and deployed. For the best experience run these commands in an elevated Windows CMD shell or PowerShell.

Windows PowerShell ISE does not work for interactive sessions with containers. Even though the container is running, it will appear to hang. First, start a container with an interactive session from the nanoserver image. Once the container has started, you will be presented with a command shell from within the container.

docker run -it microsoft/nanoserver cmd Inside the container we will create a simple ‘Hello World’ script.

powershell.exe Add-Content C:\helloworld.ps1 'Write-Host "Hello World"' When completed, exit the container.

exit You will now create a new container image from the modified container. To see a list of containers run the following and take note of the container id.

docker ps -a Run the following command to create the new ‘HelloWorld’ image. Replace with the id of your container.

docker commit helloworld When completed, you now have a custom image that contains the hello world script. This can be seen with the following command.

docker images Finally, to run the container, use the docker run command.

docker run --rm helloworld powershell c:\helloworld.ps1 The outcome of the docker run command is that a Hyper-V container was created from the 'HelloWorld' image, a sample 'Hello World' script was then executed (output echoed to the shell), and then the container stopped and removed. Subsequent Windows 10 and container quick starts will dig into creating and deploying applications in containers on Windows 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment