Skip to content

Problem launching Windows processes from inside WSL2 Docker #10883

Closed

Description

@nrclark

Windows Version

Microsoft Windows [Version 10.0.19045.3448]

WSL Version

2.0.9.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.133.1-1

Distro Version

Ubuntu 22.04

Other Software

Docker CE, version 24.0.7. Installed on WSL2 from Docker's apt repo.
Notepad.exe

Repro Steps

I am working on a project that needs to run Windows applications from inside of a WSL2 Docker container. When I try to launch a Windows application directly (notepad.exe used as an example), I get a strange failure. The failure doesn't occur if I launch it from inside of a shell instead.

Inside of WSL2 (with dockerd running as sudo in another tab), this command fails:

docker run --rm -it --privileged --mount type=bind,source=/mnt,target=/mnt \
    --mount type=bind,source=/run/WSL,target=/run/WSL \
    --mount type=bind,source=/etc/passwd,target=/etc/passwd,readonly \
    --mount type=bind,source=/etc/group,target=/etc/group,readonly \
    --mount "type=bind,source=$HOME,target=$HOME" \
    --workdir "$HOME" \
    -u $(id -u):$(id -g) \
    --env WSLENV="${WSLENV}" \
    --env WSL_DISTRO_NAME="${WSL_DISTRO_NAME}" \
    --env WSL_INTEROP="${WSL_INTEROP}" \
    --env WT_PROFILE_ID="${WT_PROFILE_ID}" \
    --env WT_SESSION="${WT_SESSION}" \
    ubuntu \
    '/mnt/c/Windows/system32/notepad.exe'

with the following error:

<3>WSL (1) ERROR: ConfigInitializeEntry:1621: Failed to mount (null) at /dev as devtmpfs 1

but this one succeeds OK:

docker run --rm -it --privileged --mount type=bind,source=/mnt,target=/mnt \
    --mount type=bind,source=/run/WSL,target=/run/WSL \
    --mount type=bind,source=/etc/passwd,target=/etc/passwd,readonly \
    --mount type=bind,source=/etc/group,target=/etc/group,readonly \
    --mount "type=bind,source=$HOME,target=$HOME" \
    --workdir "$HOME" \
    -u $(id -u):$(id -g) \
    --env WSLENV="${WSLENV}" \
    --env WSL_DISTRO_NAME="${WSL_DISTRO_NAME}" \
    --env WSL_INTEROP="${WSL_INTEROP}" \
    --env WT_PROFILE_ID="${WT_PROFILE_ID}" \
    --env WT_SESSION="${WT_SESSION}" \
    ubuntu \
    sh -c '/mnt/c/Windows/system32/notepad.exe'

Interestingly, I also see that bash -c '/mnt/c/Windows/system32/notepad.exe' fails in the same way, even though sh -c '/mnt/c/Windows/system32/notepad.exe' works just fine. I can also make a script with the contents of:

#!/bin/bash
/mnt/c/Windows/system32/notepad.exe "$@"

and run that instead of a shell, and it works as expected.
What's going on here? Can anybody help me out with a workaround?

Expected Behavior

In all cases, notepad should launch identically.

Actual Behavior

Launching notepad.exe from sh/dash works, as does putting it in a shell-script that runs under bash. Launching it directly fails, as does launching it from bash (even though that works when placed in a script).

All failures produce this message on stderr:

<3>WSL (1) ERROR: ConfigInitializeEntry:1621: Failed to mount (null) at /dev as devtmpfs 1

Diagnostic Logs

I couldn't think of any useful dianostic logs. Let me know if there's anything specific that you'd like to see.

Activity

  1. github-actions commented on Dec 6, 2023

    @github-actions
    Contributor

    Hi I'm an AI powered bot that finds similar issues based off the issue title.

    Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

    Open similar issues:

    Closed similar issues:

    Note: You can give me feedback by thumbs upping or thumbs downing this comment.

  2. OneBlue commented on Dec 7, 2023

    @OneBlue
    Collaborator

    /logs

  3. nrclark commented on Dec 8, 2023

    @nrclark
    Author

    Logfiles are attached here. During recording, I captured one successful launch (asking Docker to run sh -c '/mnt/c/Windows/system32/notepad.exe') and one failed launch (asking Docker to run /mnt/c/Windows/system32 directly) WslLogs-2023-12-08_00-30-10.zip

  4. OneBlue commented on Dec 8, 2023

    @OneBlue
    Collaborator

    Thank you nrclark. The issue is that the executable that runs windows executables has special logic when its pid is 1, and inside a docker container it will behave that if it's the first process.

    This is a bug, but until it's fixed you can work around it like this:

    docker run --rm -it --privileged --mount type=bind,source=/mnt,target=/mnt \
        --mount type=bind,source=/run/WSL,target=/run/WSL \
        --mount type=bind,source=/etc/passwd,target=/etc/passwd,readonly \
        --mount type=bind,source=/etc/group,target=/etc/group,readonly \
        --mount "type=bind,source=$HOME,target=$HOME" \
        --workdir "$HOME" \
        -u $(id -u):$(id -g) \
        --env WSLENV="${WSLENV}" \
        --env WSL_DISTRO_NAME="${WSL_DISTRO_NAME}" \
        --env WSL_INTEROP="${WSL_INTEROP}" \
        --env WT_PROFILE_ID="${WT_PROFILE_ID}" \
        --env WT_SESSION="${WT_SESSION}" \
        ubuntu \
        bash -c '/mnt/c/Windows/system32/notepad.exe && echo done'
    
  5. nrclark commented on Dec 9, 2023

    @nrclark
    Author

    Thanks Blue (@OneBlue). I also noticed something else that might be related. When I have systemd enabled in wsl.conf, I can't run Windows processes from inside of Docker at all. Running this:

    docker run --rm -it --privileged --mount type=bind,source=/mnt,target=/mnt \
        --mount type=bind,source=/run/WSL,target=/run/WSL \
        --mount type=bind,source=/etc/passwd,target=/etc/passwd,readonly \
        --mount type=bind,source=/etc/group,target=/etc/group,readonly \
        --mount "type=bind,source=$HOME,target=$HOME" \
        --workdir "$HOME" \
        -u $(id -u):$(id -g) \
        --env WSLENV="${WSLENV}" \
        --env WSL_DISTRO_NAME="${WSL_DISTRO_NAME}" \
        --env WSL_INTEROP="${WSL_INTEROP}" \
        --env WT_PROFILE_ID="${WT_PROFILE_ID}" \
        --env WT_SESSION="${WT_SESSION}" \
        ubuntu \
        sh -c '/mnt/c/Windows/system32/notepad.exe'
    

    gives me a different error than before. Instead of that /dev error, I get this interesting one instead:

    sh: 1: /mnt/c/Windows/system32/notepad.exe: not found.
    

    Note that if I run sh -c 'ls /mnt/c/Windows/system32/notepad.exe' instead, the executable is -detected- OK, so it's definitely still getting mounted into my Docker container without issue.

    This error occurs when:

    1. Systemd is enabled and running.

    2. Docker is installed and active. It doesn't matter which Docker version I use (Ubuntu's packages or Docker.io's packages), or whether I run the service using systemctl start docker or manually using service docker start. When using service docker start, it also doesn't matter whether I do it from inside of a shell or whether I do it via wsl.exe from Windows via cmd.exe.

    3. I try to run any Windows process from inside of a Docker image, even through methods that work when systemd is disabled. This fails every time, with an stderr that it can't find the file. Note that I can see the file on the filesystem OK.

    I took a log capture of this happening and attached it to this ticket.
    WslLogs-2023-12-08_22-14-56.zip

  6. ndreys commented on Dec 10, 2023

    @ndreys

    nrclark does adding

    -v /init:/init:ro
    

    or equivalent --mount incantation to your docker run help? I think I might have just had the pleasure of running into exactly the same issue and from what I can tell the problem is that WSLInterop registers /init as interpreter:

    cat /proc/sys/fs/binfmt_misc/WSLInterop
    enabled
    interpreter /init
    flags: PF
    offset 0
    magic 4d5a
    

    but /init isn't present in the container AKA ENOENT/"file not found". Adding explicit bind-mount resolved the problem in my case.

    I could swear this used to work without, but now I'm starting to doubt my memory. 🤷

  7. nrclark commented on Dec 11, 2023

    @nrclark
    Author

    Andrey Smirnov (@ndreys) thanks for the pro-tip! You're right, that got .exe execution working under Docker when systemd is active. It's interesting that .exe execution works in non-systemd Docker without the explicit /init binding - maybe some more PID1 trickery.

    The main issue in my ticket is still active though, and is unrelated to the secondary issue that Andrey Smirnov (@ndreys) addressed.

  8. benhillis commented on Jan 8, 2024

    @benhillis
    Member
  9. djc5166 commented on Oct 24, 2025

    @djc5166

    Trying to understand what I am doing wrong here. Followed all of the above but my windows binaries always throw

    <3>WSL (12 - ) ERROR: UtilBindVsockAnyPort:307: socket failed 38

    WSL version: 2.6.2.0
    Kernel version: 6.6.87.2-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions