# Install Docker on Windows Server 2016 using win\_shell module

**URL:** <https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009>\
**Category:** Ansible Project\
**Tags:** windows, ubuntu, ee\
**Created:** [July 17, 2017, 9:51pm UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009 "2017-07-17T21:51:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pasquale\_Carlo\_Maior](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@Pasquale\_Carlo\_Maior](https://forum.ansible.com/u/Pasquale_Carlo_Maior)\
**Post date:** [July 17, 2017, 9:51pm UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/1 "2017-07-17T21:51:06Z")

</div>

**ISSUE TYPE**

- Bug Report

**COMPONENT NAME**  
Win\_shell

**ANSIBLE VERSION**

`ansible 2.3.0.0 config file = /home/<my-user>/ansible-docker/ansible.cfg (just disabled host key checking) configured module search path = Default w/o overrides python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]`

##### CONFIGURATION

`  
host\_key\_checking = False

`

**OS / ENVIRONMENT**  
Control Machine: Ubuntu 16.04 machine  
Guest Machine: Windows Server 2016

**SUMMARY**

Could not install Docker for Windows using the same commands indicated on docker interactive installation on docker website([Windows | Docker Docs](https://docs.docker.com/engine/installation/windows/docker-ee/)).

**STEPS TO REPRODUCE**

Windows Server 2016, clean installation with Powershell Remoting and WinRM service enabled with basic authentication and allow unencrypted for WinRM service.

`

- hosts: windows  
tasks:
- name: Enable Windows Container Feature  
win\_feature:  
name: Containers  
state: present
- name: Install Nuget Package Provider  
win\_shell: Install-PackageProvider -Name “NuGet” -MinimumVersion “2.8.5.201” -Force
- name: Install Docker Msft Module  
win\_shell: Install-Module -Name “DockerMsftProvider” -Repository “PSGallery” -Force
- name: Install Docker package #error in this task  
win\_shell: Install-Package –ProviderName “DockerMsftProvider” -Name “Docker” -Force
- name: Start docker service #Start-Service docker  
win\_service:  
name: docker  
state: started  
start\_mode: auto  
`

**EXPECTED RESULTS**  
Docker installed and running

**ACTUAL RESULTS**  
Package manager returns an error (see stacktrace below, refered to task for installation of Docker package)

`TASK [Install Docker package] **************************************************************************************************************************************************************************** task path: /home/carlo/ansible-docker-trystack/windows_hosts.yml:11 Using module file /usr/lib/python2.7/dist-packages/ansible/modules/windows/win_shell.ps1 <192.168.87.129> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5985 TO 192.168.87.129 EXEC (via pipeline wrapper) fatal: [192.168.87.129]: FAILED! => { "changed": true, "cmd": "Install-Package –ProviderName \"DockerMsftProvider\" -Name \"Docker\" -Force", "delta": "0:00:07.845040", "end": "2017-07-17 02:53:56.827786", "failed": true, "rc": 1, "start": "2017-07-17 02:53:48.982746", "stderr": "Install-Package : No match was found for the specified search criteria and package name 'Docker'. Try \r\nGet-PackageSource to see all available registered package sources.\r\nAt line:1 c har:65\r\n+ ... ing $false; Install-Package –ProviderName \"DockerMsftProvider\" -Name ...\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex \r\n ception\r\n + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement. Cmdlets.InstallPackage", "stderr_lines": ["Install-Package : No match was found for the specified search criteria and package name 'Docker'. Try ", "Get-PackageSource to see all available registered package sources.", "At line:1 char:65", "+ ... ing $false; Install-Package –ProviderName \"DockerMsftProvider\" -Name ...", "+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", " + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex ", " ception", " + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" ], "stdout": "", "stdout_lines": [] } to retry, use: --limit @/home/carlo/ansible-docker-trystack/windows_hosts.retry`

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [July 25, 2017, 5:36am UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/2 "2017-07-25T05:36:45Z")

</div>

Hi,

I am curious if you got any further with this.

I looked at the link above but couldn’t see any powershell command like you show to install docker. It looks like there is a .msi installer now, which I would hope could be installed using the win\_package module.

The .msi installer is described on this page

[https://docs.docker.com/docker-for-windows/install/#install-docker-for-windows](https://docs.docker.com/docker-for-windows/install/#install-docker-for-windows)

---

<div class="post-metadata">

**Author:** ![Yuriy\_Ostapenko](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@Yuriy\_Ostapenko](https://forum.ansible.com/u/Yuriy_Ostapenko)\
**Post date:** [July 31, 2017, 12:14pm UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/3 "2017-07-31T12:14:21Z")

</div>

Hi,

I experienced the same issue.  
Install-Package works from both local powershell session or remote with “Enter-PSSession”, but not from Ansible.

Apparently it has something to do with how Ansible does winrm and BITS.  
Try switching to DockerMsftProviderInsider. It worked for me.

Similar issue with packer: [https://github.com/StefanScherer/packer-windows/pull/33](https://github.com/StefanScherer/packer-windows/pull/33)

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [August 1, 2017, 8:45am UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/4 "2017-08-01T08:45:55Z")

</div>

It's interesting that is worked over a PSSession but still failed with Ansible. PSSession is run over WinRM which is the same protocol Ansible uses so if it didn't fail there there must be something else going on.

---

<div class="post-metadata">

**Author:** ![Yuriy\_Ostapenko](https://avatars.discourse-cdn.com/v4/letter/y/0ea827/32.png) [@Yuriy\_Ostapenko](https://forum.ansible.com/u/Yuriy_Ostapenko)\
**Post date:** [August 1, 2017, 11:00am UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/5 "2017-08-01T11:00:57Z")

</div>

Strange indeed.

At least one difference would be that PSSession sends encrypted winrm payload over http, while ansible runs unencrypted winrm over https port, afaik.

---

<div class="post-metadata">

**Author:** ![Andreas\_Mosti](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Andreas\_Mosti](https://forum.ansible.com/u/Andreas_Mosti)\
**Post date:** [January 18, 2018, 10:29am UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/6 "2018-01-18T10:29:14Z")

</div>

Can you paste the Ansible-tasks you got working? Seeing the same issues here…

mandag 31. juli 2017 14.14.21 UTC+2 skrev Yuriy Ostapenko følgende:

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [January 19, 2018, 6:10am UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/7 "2018-01-19T06:10:24Z")

</div>

Not sure if this will help you or not but you might be able to get some ideas from my Ansible role for Windows Docker installation.

[https://github.com/mrlesmithjr/ansible-windows-docker](https://github.com/mrlesmithjr/ansible-windows-docker)

---

<div class="post-metadata">

**Author:** ![Andreas\_Mosti](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Andreas\_Mosti](https://forum.ansible.com/u/Andreas_Mosti)\
**Post date:** [January 19, 2018, 8:02am UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/8 "2018-01-19T08:02:53Z")

</div>

I got it working from the powershell-module with the following tasks:

- name: Enable Windows Container Feature  
win\_feature:  
name: Containers  
state: present  
register: dockerwindowsfeature

- name: Reboot server if Windows Container Feature requires it  
win\_reboot:  
when: dockerwindowsfeature.reboot\_required

- name: Add DockerMsftProviderInsider powershell module repository  
win\_psmodule:  
name: DockerMsftProviderInsider  
state: present

- name: Install Docker package  
win\_shell: Install-Package –ProviderName “DockerMsftProviderInsider” -Name “Docker” -Force  
args:  
creates: “C:\Program Files\Docker\metadata.json”  
register: dockerinstall

- name: Reboot server if Docker package requires it  
win\_reboot:  
when: dockerinstall.changed

Might help somebody out.

fredag 19. januar 2018 07.10.24 UTC+1 skrev Larry Smith følgende:

---

<div class="post-metadata">

**Author:** ![Larry\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@Larry\_Smith1](https://forum.ansible.com/u/Larry_Smith1)\
**Post date:** [January 19, 2018, 1:22pm UTC](https://forum.ansible.com/t/install-docker-on-windows-server-2016-using-win-shell-module/25009/9 "2018-01-19T13:22:05Z")

</div>

Awesome. Glad you got it sorted out.
