You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过命令暴露Docker for Windows守护进程?含WSL配置与磁盘共享需求

Hey there! Let's tackle your Docker for Windows command-line questions one by one, skipping all those GUI clicks:

1. Expose Docker daemon on tcp://localhost:2375 via command line (no GUI)

Absolutely! Docker Desktop for Windows stores its core configuration in %APPDATA%\Docker\settings.json. You can modify this file with PowerShell to enable the unencrypted TCP endpoint, then restart the service to apply changes. Here's how:

  1. First, stop the Docker Desktop service if it's running:
    Stop-Service "Docker Desktop Service"
    
  2. Update the settings to add the TCP host entry. This script checks if the hosts property exists, adds it if not, and appends the TCP endpoint if it's missing:
    $settingsPath = "$env:APPDATA\Docker\settings.json"
    $settings = Get-Content $settingsPath | ConvertFrom-Json
    
    if (-not $settings.PSObject.Properties['hosts']) {
        # Initialize hosts with default npipe + TCP endpoint
        $settings | Add-Member -MemberType NoteProperty -Name "hosts" -Value @("npipe:////./pipe/docker_engine", "tcp://0.0.0.0:2375")
    } else {
        # Add TCP endpoint only if it's not already present
        if ($settings.hosts -notcontains "tcp://0.0.0.0:2375") {
            $settings.hosts += "tcp://0.0.0.0:2375"
        }
    }
    
    # Save the updated settings
    $settings | ConvertTo-Json -Depth 10 | Set-Content $settingsPath
    
  3. Restart the Docker Desktop service to apply the change:
    Start-Service "Docker Desktop Service"
    

⚠️ Important Security Note: Enabling unencrypted TCP (no TLS) exposes your Docker daemon to potential risks. Only use this setup in trusted, local development environments.

2. Command-line alternative to the GUI toggle for WSL Docker setup

The GUI step you mentioned (enabling the TCP endpoint) can be replaced with the command-line method from question 1. You can also automate the WSL environment variable setup without touching any GUIs:

  • From Windows PowerShell, append the DOCKER_HOST export to your WSL user's .bashrc (replace your_username with your actual WSL username—get it via wsl whoami):
    wsl -u your_username echo 'export DOCKER_HOST=tcp://localhost:2375' >> ~/.bashrc
    
  • To apply the change immediately in an active WSL session, run:
    source ~/.bashrc
    

Now you can run Docker commands directly in WSL without ever opening the Docker Desktop settings GUI.

3. Command-line solution for Docker disk sharing

Docker Desktop's drive sharing is also controlled via the settings.json file. Use PowerShell to enable shared drives without the GUI:

  1. Stop the Docker Desktop service first:
    Stop-Service "Docker Desktop Service"
    
  2. Update the sharedDrives section to enable the drives you want to share. For example, to share the C drive:
    $settingsPath = "$env:APPDATA\Docker\settings.json"
    $settings = Get-Content $settingsPath | ConvertFrom-Json
    
    if (-not $settings.PSObject.Properties['sharedDrives']) {
        # Initialize shared drives with C: enabled
        $settings | Add-Member -MemberType NoteProperty -Name "sharedDrives" -Value @{ "C" = $true }
    } else {
        # Enable C: drive sharing
        $settings.sharedDrives["C"] = $true
        # Add more drives if needed, e.g.:
        # $settings.sharedDrives["D"] = $true
    }
    
    # Save the changes
    $settings | ConvertTo-Json -Depth 10 | Set-Content $settingsPath
    
  3. Restart the Docker Desktop service:
    Start-Service "Docker Desktop Service"
    

ℹ️ Note: The first time you access the shared drive from a container, Docker may prompt you for your Windows credentials to verify you have permission to access the drive. This is a standard security check.


内容的提问来源于stack exchange,提问作者AnjK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:39:40