Docker on Windows
上QQ阅读APP看书,第一时间看更新

Docker Desktop

Docker Desktop is available from Docker Hub – you can find it by navigating to https://dockr.ly/docker-for-windows. You can choose between the Stable channel and the Edge channel. Both channels give you the community Docker Engine, but the Edge channel follows the monthly release cycle, and you will get experimental features. The Stable channel tracks the Docker Engine release cycle, with quarterly updates.

You should use the Edge channel in development if you want to work with the latest features. In test and production, you will use Docker Enterprise, so you need to be careful that you don't use features in development, which are not yet available in Enterprise. Docker recently announced Docker Desktop Enterprise, which lets developers run the exact same engine locally as their organization is running in production.

You need to download and run the installer. The installer will verify that you can run Docker in your setup and will configure the Windows features needed to support Docker. When Docker is running, you will see a whale icon in the notification bar, which you can right-click on for options:

You need to select Switch to Windows containers... before you do anything else. Docker Desktop on Windows can run Linux containers by running Docker inside a Linux VM on your machine. This is great for testing out Linux apps to see how they run in containers, but this book is all about Windows containers – so switch over, and Docker will remember this setting in future.

While Docker for Windows is running, you can open Command Prompt or a PowerShell session and start working with containers. First, verify that everything is working as expected by running docker version. You should see an output similar to this code snippet:

> docker version

Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.24)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:28:48 2019
OS/Arch: windows/amd64
Experimental: true
The output tells you the version of the command-line client and the Docker Engine. The operating system field should read Windows for both; if not, then you may still be in Linux mode, and you'll need to switch to Windows containers.

Now run a simple container with the Docker CLI:

docker container run dockeronwindows/ch01-whale:2e

This uses a public image on Docker Hub – one of the sample images for this book, which Docker will pull the first time you use it. If you don't have any other images, this will take a few minutes, as it will also download the Microsoft Nano Server image, which my image uses as a base. When the container runs, it shows some ASCII art and then exits. Run the same command again, and you will see that it executes much more quickly as the images are now cached locally.

Docker Desktop checks for updates when it starts and will prompt you to download a new version when it's ready. You can keep your Docker tools up to date just by installing new versions when they're released. You can check the current versions you have installed by selecting About Docker Desktop from the taskbar menu:

That's all the setup you need. Docker Desktop also contains the Docker Compose tool I'll be using later in the book, so you're all set to follow along with the code samples.