# Issue with Running Docker Compose on Windows via Ansible from Ubuntu

**URL:** <https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123>\
**Category:** Get Help\
**Tags:** windows, ansible-project, ubuntu\
**Created:** [February 7, 2025, 5:20pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123 "2025-02-07T17:20:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumeysa\_yuk](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rumeysa_yuk/32/7507_2.png) [@rumeysa\_yuk](https://forum.ansible.com/u/rumeysa_yuk)\
**Post date:** [February 7, 2025, 5:20pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/1 "2025-02-07T17:20:13Z")

</div>

I am trying to manage a Windows machine from Ubuntu using Ansible. I am able to successfully transfer my target files, including Docker Compose files, to the Windows machine. However, when I try to start the Docker Compose files via Ansible, I encounter the following error:

```auto
error getting credentials - err: exit status 1, out: The specified session does not exist. It may have been closed earlier.

```

When I manually run the docker compose up -d command on the Windows machine, it works successfully.

Setup:

Ansible Playbook:

- Install Docker on the Windows machine
- Copy the necessary files Start  
the application with Docker Compose

Defaults:

- I am connecting to the Windows machine via WinRM.
- Docker Desktop is installed on the Windows machine.
- I face issues running docker compose via Ansible, but it works when I  
run it manually on the Windows machine.

docker-compose.yml file:

```auto
---
- name: Deploy Redis on Windows
  hosts: redis_hosts
  vars_files:
    - ./vars.yml

  tasks:
    - name: Ensure Docker is installed
      win_chocolatey:
        name: docker-desktop
        state: present

    - name: Create application directory
      win_file:
        path: "{{ app_files_dest }}"
        state: directory

    - name: Copy application files
      win_copy:
        src: "{{ app_files_src }}/"
        dest: "{{ app_files_dest }}"

 
    - name: Start the application with Docker Compose
      win_command: docker compose -f redis.yml up -d
      args:
        chdir: "{{ app_files_dest }}"

```

inventory.ini:

> [windows]  
> 192.168.2.152 ansible\_user=w10 ansible\_password=1 ansible\_connection=winrm ansible\_winrm\_transport=basic ansible\_port=5985 ansible\_winrm\_scheme=http

vars.yml:

> app\_files\_src: “{{ file\_path }}/cache”

> app\_files\_dest: ‘C:\app\cache’

Why do I encounter this error when running docker compose via Ansible? How can I resolve this issue?

---

<div class="post-metadata">

**Author:** ![markuman](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@markuman](https://forum.ansible.com/u/markuman)\
**Post date:** [February 7, 2025, 8:25pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/2 "2025-02-07T20:25:19Z")

</div>

Configuring windows via ansible is possible. but feels like gambling.

What works for me sometimes is switching to `win_shell` with parameter `executable: powershell.exe`.

---

<div class="post-metadata">

**Author:** ![bvitnik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bvitnik/32/4132_2.png) [@bvitnik](https://forum.ansible.com/u/bvitnik)\
**Post date:** [February 7, 2025, 9:57pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/3 "2025-02-07T21:57:40Z")

</div>

> [@markuman](#):
>
> Configuring windows via ansible is possible. but feels like gambling.

I just wanted to quote this as the best description of Windows + Ansible experience I have seen… and it put a big smile on my face 😂

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [February 8, 2025, 12:40pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/4 "2025-02-08T12:40:37Z")

</div>

The community.docker collection does not support Windows (see the README: [Ansible Galaxy](https://galaxy.ansible.com/ui/repo/published/community/docker/)).

I don’t know what’s the current state of running Python modules on Windows (outside of WSL), but all modules in that collection are Python modules. There are no PowerShell / CSharp modules in the collection. My _guess_ is that the error you’re seeing,

> [@rumeysa\_yuk](#):
>
> ```auto
> error getting credentials - err: exit status 1, out: The specified session does not exist. It may have been closed earlier.
> 
> ```

basically means that Python modules still don’t work under Windows.

---

<div class="post-metadata">

**Author:** ![markuman](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@markuman](https://forum.ansible.com/u/markuman)\
**Post date:** [February 8, 2025, 4:40pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/5 "2025-02-08T16:40:08Z")

</div>

> [@felixfontein](#):
>
> basically means that Python modules still don’t work under Windows.

The user is using raw win cmd commands. Thats imho not a python/comminuty.docker issue.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [February 8, 2025, 6:15pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/6 "2025-02-08T18:15:54Z")

</div>

Oops, I misread that… I’m going to blame that on still recovering from the flu… 🙂

---

<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:** [February 9, 2025, 11:43pm UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/7 "2025-02-09T23:43:36Z")

</div>

> [@rumeysa\_yuk](#):
>
> `The specified session does not exist`

This would indicate that the `docker.exe` command is trying to access something like the user’s secret store or something else not typically available over a network logon (WinRM/SSH will all produce a network logon). You most likely have a few options to get this working:

- Use a auth type that does cred delegation, CredSSP for winrm/psrp, password plaintext auth for ssh
- Use become on the task with either the become user being SYSTEM or the same ansible\_user/ansible\_password
- See if the `docker.exe compose` step has something to avoid trying to access the DPAPI store
- Try using `command` through the local connection plugin

The first two options are ways to pretend to be an interactive user and run commands like it would work locally. Reading online it looks like there’s some setting like `"credsStore": "secretservice"` that could be the culprit in the docker config file. Maybe removing it or seeing if there are other options might work if you don’t need the credential store.

The last option works but only if the playbook is run through WSL:

```yaml
- name: run docker compose through localhost
  command: docker.exe compose -f redis.yml up -d
  delegate_to: localhost 

```

As WSL can execute Windows binaries natively this should work, if it can’t find `docker.exe` in the Linux `PATH` env var this may work to spawn a sub shell in Windows that can find `docker.exe`

```yaml
- name: run docker compose through localhost
  shell: docker.exe compose -f redis.yml up -d
  args:
    executable: /mnt/c/Windows/System32/cmd.exe
    chdir: /mnt/c/...
  delegate_to: localhost 

```

---

<div class="post-metadata">

**Author:** ![rumeysa\_yuk](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rumeysa_yuk/32/7507_2.png) [@rumeysa\_yuk](https://forum.ansible.com/u/rumeysa_yuk)\
**Post date:** [February 10, 2025, 6:25am UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/8 "2025-02-10T06:25:59Z")

</div>

Hi,Thank you for all the answers. I found the solution to the problem and ı am using winrm. The problem was solved when I added the values ​​  
become=yes  
become\_user=w10  
to my windows host in my inventory.ini file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 12, 2025, 6:26am UTC](https://forum.ansible.com/t/issue-with-running-docker-compose-on-windows-via-ansible-from-ubuntu/40123/9 "2025-03-12T06:26:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
