簡體   English   中英

從 Windows 主機連接到 wsl2 Ubuntu docker

[英]Connect to wsl2 Ubuntu docker from Windows host

我有 Windows 10 並安裝了 Docker 桌面。 在他們更改商業使用條款后,我決定刪除 Docker 桌面安裝並僅使用 docker 引擎本身(因為我沒有使用 GUI)。 我已經在 WSL 2 下的docker上安裝了 docker 並且工作正常:

localusr@MACHINE:~$ docker context ls
NAME            DESCRIPTION                               DOCKER ENDPOINT                             KUBERNETES ENDPOINT   ORCHESTRATOR
default *       Current DOCKER_HOST based configuration   unix:///mnt/wsl/shared-docker/docker.sock                         swarm
desktop-linux                                             npipe:////./pipe/dockerDesktopLinuxEngine
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.
localusr@MACHINE:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

localusr@MACHINE:~$

現在我想讓我的 JetBrains IDE 連接到 Docker 引擎。 我有以下選擇: 在此處輸入圖像描述

那么配置連接的最佳方法是什么? 我可以以某種方式“創建鏈接”到 pipe 以將Docker for Windows選項嗎? 似乎它只是試圖連接到npipe:////./pipe/docker_engine 或者我可以公開 TCP/SSH 端口。

我是配置 docker 的新手,所以請說明我可以使用哪個選項。

免責聲明:不是專家,只是遇到了完全相同的問題並像這樣解決了它。

默認情況下,docker 守護程序已啟動,僅在 unix 套接字上公開。
據我所知,沒有辦法在 intellij 中直接指定 unix 套接字,而是在 windows 部分需要一些解決方法,我不知道這需要做多少工作。

You may configure the daemon to also expose itself via a tcp socket, for example same tcp socket that you used with docker desktop ( tcp://localhost:2375 ).
設置完成后,您可以再次配置 intellij 以通過 tcp 與 docker 守護進程交互。
請注意將 docker 守護程序暴露於網絡所涉及的安全問題。

  1. 確保 docker 已安裝並正常工作(即docker run hello-world
  2. 創建文件/etc/docker/daemon.json
    與: { "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"] }
    請注意,unix 插座仍用於 ubuntu 內的任何 docker 操作
  3. 重啟 docker 服務,使配置生效: sudo service docker restart
  4. 驗證 docker 是否正常

用過的:
wsl 2,ubuntu 20.04,windows 10.0.19043
docker 安裝按照: https://docs.docker.com/engine/install/ubuntu/
警告:systemd 目前並沒有完全在 wsl2 上開箱即用,因此某些選項可能不可用。

由於 wsl2 處理 windows 和 wsl2 之間文件傳輸的方式,這個新的工作流程:“ubuntu 中的 docker”可能與您以前的體驗大不相同。
您可能需要考慮將所有文件移動到 ubuntu 或通過某種方式在 windows 上運行 docker。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM