https://blog.docker.com/2016/09/build-your-first-docker-windows-server-container/
-- via my feedly newsfeed
Today, Microsoft announced the general availability of Windows Server 2016, and with it, Docker engine running containers natively on Windows. This blog post describes how to get setup to run Docker Windows Containers on Windows 10 or using a Windows Server 2016 VM. Check out the companion blog posts on the technical improvements that have made Docker containers on Windows possible and the post announcing the Docker Inc. and Microsoft partnership.
Before getting started, It's important to understand that Windows Containers run Windows executables compiled for the Windows Server kernel and userland (either windowsservercore or nanoserver). To build and run Windows containers, you have to have a Windows system with container support.
Windows 10 with Anniversary Update
For developers, Windows 10 is a great place to run Docker Windows containers and containerization support was added to the the Windows 10 kernel with the Anniversary Update (note that container images can only be based on Windows Server Core and Nanoserver, not Windows 10). All that's missing is the Windows-native Docker Engine and some image base layers.
The simplest way to get a Windows Docker Engine is by installing the Docker for Windows public beta (direct download link). Docker for Windows used to only setup a Linux-based Docker development environment (slightly confusing, we know), but the public beta version now sets up both Linux and Windows Docker development environments, and we're working on improving Windows container support and Linux/Windows container interoperability.
With the public beta installed, the Docker for Windows tray icon has an option to switch between Linux and Windows container development. For details on this new feature, check out Stefan Scherers blog post.
Switch to Windows containers and skip the next section.
Windows Server 2016
Windows Server 2016 is the where Docker Windows containers should be deployed for production. For developers planning to do lots of Docker Windows container development, it may be worth setting up a Windows Server 2016 dev system (in a VM, for example), at least until Windows 10 and Docker for Windows support for Windows containers matures.
For Microsoft Ignite 2016 conference attendees, USB flash drives with Windows Server 2016 preloaded are available at the expo. Not at ignite? Download a free evaluation version and install it on bare metal or in a VM running on Hyper-V, VirtualBox or similar. Running a VM with Windows Server 2016 is also a great way to do Docker Windows container development on macOS and older Windows versions.
Once Windows Server 2016 is running, log in and install the Windows-native Docker Engine directly (that is, not using "Docker for Windows"). Run the following in an Administrative PowerShell prompt:
# Add the containers feature and restart Install-WindowsFeature containers Restart-Computer -Force # Download, install and configure Docker Engine Invoke-WebRequest "https://download.docker.com/components/engine/windows-server/cs-1.12/docker.zip" -OutFile "$env:TEMP\docker.zip" -UseBasicParsing Expand-Archive -Path "$env:TEMP\docker.zip" -DestinationPath $env:ProgramFiles # 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) # You have to start a new PowerShell prompt at this point dockerd --register-service Start-Service docker
Docker Engine is now running as a Windows service, listening on the default Docker named pipe. For development VMs running (for example) in a Hyper-V VM on Windows 10, it might be advantageous to make the Docker Engine running in the Windows Server 2016 VM available to the Windows 10 host:
# 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) dockerd.exe -H npipe:////./pipe/docker_engine -H 0.0.0.0:2375 --register-service
The Windows Server 2016 Docker engine can now be used from the VM host by setting DOCKER_HOST
:
$env:DOCKER_HOST = "<ip-address-of-vm>:2375"
See the Microsoft documentation for more comprehensive instructions.
Running Windows containers
First, make sure the Docker installation is working:
> docker version Client: Version: 1.12.1 API version: 1.24 Go version: go1.6.3 Git commit: 23cf638 Built: Thu Aug 18 17:32:24 2016 OS/Arch: windows/amd64 Experimental: true Server: Version: 1.12.2-cs2-ws-beta-rc1 API version: 1.25 Go version: go1.7.1 Git commit: 62d9ff9 Built: Fri Sep 23 20:50:29 2016 OS/Arch: windows/amd64
Next, pull a base image that's compatible with the evaluation build, re-tag it and to a test-run:
docker pull microsoft/windowsservercore:10.0.14393.206 docker tag microsoft/windowsservercore:10.0.14393.206 microsoft/windowsservercore docker run microsoft/windowsservercore hostname 69c7de26ea48
Building and pushing Windows container images
Pushing images to Docker Cloud requires a free Docker ID. Storing images on Docker Cloud is a great way to save build artifacts for later user, to share base images with co-workers or to create build-pipelines that move apps from development to production with Docker.
Docker images are typically built with docker build from a Dockerfile recipe, but for this example, we're going to just create an image on the fly in PowerShell.
"FROM microsoft/windowsservercore `n CMD echo Hello World!" | docker build -t <docker-id>/windows-test-image -
Test the image:
docker run <docker-id>/windows-test-image Hello World!
Login with docker login
and then push the image:
docker push <docker-id>/windows-test-image
Images stored on Docker Cloud available in the web interface and public images can be pulled by other Docker users.
Using docker-compose on Windows
Docker Compose is a great way develop complex multi-container consisting of databases, queues and web frontends. Compose support for Windows is still a little patchy and only works on Windows Server 2016 at the time of writing (i.e. not on Windows 10).
To try out Compose on Windows, you can clone a variant of the ASP.NET Core MVC MusicStore app, backed by a SQL Server Express 2016 database. If running this sample on Windows Server 2016 directly, first grab a Compose executable and make it is in your path. A correctly tagged microsoft/windowsservercore
image is required before starting. Also note that building the SQL Server image will take a while.
git clone https://github.com/friism/Musicstore ... cd Musicstore docker build -t sqlserver:2016 -f .\docker\mssql-server-2016-express\Dockerfile .\docker\mssql-server-2016-express\. ... docker-compose -f .\src\MusicStore\docker-compose.yml up ...
Start a browser and open http://<ip-of-vm-running-docker>:5000/
to see the running app.
Summary
This post described how to get setup to build and run native Docker Windows containers on both Windows 10 and using the recently published Windows Server 2016 evaluation release. To see more example Windows Dockerfiles, check out the Golang, MongoDB and Python Docker Library images.
Please share any Windows Dockerfiles or Docker Compose examples your build with @docker on Twitter using the tag #windows. And don't hesitate to reach on the Docker Forums if you have questions.
More Resources:
- Sign up to be notified of GA and the Docker Datacenter for Windows Beta
- Register for a webinar: Docker for Windows Server
- Learn more about the Docker and Microsoft partnership
Build and run your first #Docker @Windows #Server #container
Click To Tweet
The post Build and run your first Docker Windows Server container appeared first on Docker Blog.
No comments:
Post a Comment