Chat Zalo Chat Messenger Phone Number Đăng nhập
Configure Docker in Windows - Microsoft Learn

Configure Docker in Windows – Microsoft Learn

Applies To: Windows Server 2022, Windows Server 2019, Windows Server 2016

The Docker engine and client are not included with Windows and must be installed and configured individually. In addition, the Docker engine can accept many custom configurations. Some examples include configuring how the daemon accepts incoming requests, default network options, and debugging/logging settings. In Windows, these settings can be specified in a configuration file or by using the Windows Service Control Manager. This document details how to install and configure the Docker engine and also provides some examples of commonly used configurations.

Install

Docker

You need Docker to work with Windows containers. Docker consists of the Docker engine (dockerd.exe) and the Docker client (docker.exe). The easiest way to install everything is in the quick start guide, which will help you set everything up and run your first container.

Install Docker

For scripted installations, see Use a script to

install Docker EE. Before you can use

  • Docker

, you’ll need to install the container images. For more information, see the documents in our container base images.

Configure

Docker with a configuration file

The preferred method for configuring the Docker engine on Windows is to use a configuration file. The configuration file can be found at ‘C:ProgramDataDockerconfigdaemon.json’. You can create this file if it does not already exist.

{ “authorization-plugins”: [], “dns”: [], “dns-opts”: [], “dns-search”: [], “exec-opts”: [], “storage-driver”: “”, “storage-opts”: [], “labels”: [], “log-driver”: “”, “mtu”: 0, “pidfile”: “”, “data-root”: “”, “cluster-store”: “”, “cluster-advertise”: “”, “debug”: true, “hosts”: [], “log-level”: “”, “tlsverify”: true, “tlscacert”: “”, “tlscert”: “”, “tlskey”: “”, “group”: “”, “default-ulimits”: {}, “bridge”: “”, “fixed-cidr”: “”, “raw-logs”: false, “registry-mirrors”: [], “insecure-registries”: [], “disable-legacy-registry”: false }

You just need to add the desired configuration changes to the configuration file. For example, the following example configures the Docker engine to accept incoming connections on port 2375. All other settings will use default values.

{ “hosts”: [“tcp://0.0.0.0:2375”] }

Similarly, the following example configures the Docker daemon to keep images and containers in an alternate path. If not specified, the default value is c:programdatadocker.

{ “data-root”: “d:\docker” }

The following example configures the Docker daemon to accept only secure connections over port 2376.

{ “hosts”: [“tcp://0.0.0.0:2376”, “npipe://”], “tlsverify”: true, “tlscacert”: “C:\ProgramData\docker\certs.d\ca.pem”, “tlscert”: “C:\ProgramData\docker\certs.d\server-cert.pem”, “tlskey”: “C:\ProgramData\docker\certs.d\server-key.pem”, }

Configure

Docker in the Docker service The Docker engine

can also be configured by modifying the Docker service with sc config. With this method, Docker Engine flags are set directly in the Docker service. Run the following command at a command prompt (cmd.exe not PowerShell):

sc config docker binpath= “”C:Program Filesdockerdockerd.exe” -run-service -H tcp://0.0.0.0:2375″

Common

configuration

The following configuration file examples show common Docker configurations. These can be combined into a single configuration file.

Default network creation

To configure the Docker engine not to

create a default NAT network, use the following configuration

. { “bridge” : “none” }

For more information, see Managing Docker Networks

.

Set Docker security group

When you are logged in to the Docker host and run Docker commands locally, these commands are executed through a named pipe. By default, only members of the Administrators group can access the Docker engine through the named pipeline. To specify a security group that has this access, use the group flag.

{ “group” : “docker” }

Proxy settings

To set proxy information for Docker

search and Docker extraction, create a Windows environment variable with the name HTTP_PROXY or HTTPS_PROXY and a proxy information value. This can be completed with PowerShell using a command similar to this

: [Environment]::SetEnvironmentVariable(“HTTP_PROXY”, “http://username:password@proxy:port/”, [EnvironmentVariableTarget]::Machine)

Once the variable is set, restart the Docker service.

Restart-Service docker

For more information, see Windows configuration file

in Docker.com. How to uninstall Docker

This section will tell you how to uninstall Docker and perform a full cleanup of Docker system components from your Windows 10 or Windows Server 2016 system

. Prepare your system for Docker

removal

Before

uninstalling Docker, make sure there are no containers running on the system.

Run the following cmdlets to check for running containers:

# Exit swarm mode (this will automatically stop and remove services and overlay networks) docker swarm leave -force # Stop all running containers docker ps -quiet | ForEach-Object {docker stop $_}

It is also recommended to remove all containers, container images, networks, and system volumes before removing Docker. To do this, run the following cmdlet:

docker system prune -volumes -all Uninstall Docker

Next, you’ll need to

uninstall Docker. To uninstall Docker on Windows 10 Go to Settings > Apps on

  • your Windows 10 machine
  • Under Apps and features, search for Docker for Windows Go to Docker for Windows
  • > Uninstall

To uninstall Docker on Windows Server 2016

:

From an elevated PowerShell session, use the Uninstall-Package and Uninstall-Module cmdlets to remove the Docker module and its corresponding package management provider from the system, as shown in the following example: Uninstall-Package -Name docker -ProviderName DockerMsftProvider Uninstall-Module – Name DockerMsftProvider

Clean up Docker data and components

After uninstalling Docker, you will need to remove the default Docker networks so that their configuration does not remain on your system after Docker is gone. To do this, run the following cmdlet:

Get-HNSNetwork | Remove-HNSNetwork

To remove default networks from Docker in Windows Server 2016.

Get-ContainerNetwork | Remove-ContainerNetwork

Run the following cmdlet to remove the Docker program data from the system

: Remove-Item “C:ProgramDataDocker” -Recurse

You may also want to remove the optional Windows features associated with Docker/containers in Windows

.

This includes the “Containers” feature, which is automatically enabled on any Windows 10 or Windows Server 2016 when Docker is installed. It can also include the “Hyper-V” feature, which is automatically enabled in Windows 10 when Docker is installed, but must be explicitly enabled in Windows Server 2016.

To remove

Windows features in Windows 10: Go

  • to Control Panel > Programs > Programs and Features > Turn Windows features on or off
  • . Find the name of the feature or features that you want to disable,

  • in this case, Containers and (optionally) Hyper-V
  • .

  • Uncheck the box next to the name of the feature you want to disable.
  • Select “OK”

To remove Windows features in Windows

Server 2016

: From an elevated PowerShell session, run the

following cmdlets to disable containers and (optionally) system Hyper-V features: Remove-WindowsFeature Containers Remove-WindowsFeature Hyper-V

Restart the system

To finish the uninstall and cleanup, run the following cmdlet from an elevated PowerShell session to restart the system: Restart-Computer –

Force

Contact US