vscode连接远程docker

  • 开启远程docker

vim /etc/docker/daemon.json

{
  "hosts": ["tcp://0.0.0.0:39012", "unix:///var/run/docker.sock"]
}

# 原文
{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"],
  "hosts": ["tcp://0.0.0.0:39012", "unix:///var/run/docker.sock"]
}


# 或者在启动参数dockerd增加-H参数(systemctl文件里面)
-H tcp://0.0.0.0:39012
  • 重启远程docker

systemctl daemon-reload
systemctl restart docker
  • 安装扩展

ms-azuretools.vscode-docker
  • 配置 设置host即可

# 配置为tcp能连接上shell
"docker.host": "tcp://127.0.0.1:39012"
# 配置DOCKER_HOST让本地docker命令使用远程的连接(wsl)
export DOCKER_HOST=tcp://192.168.1.244:39012

# 推荐vscode搭配windows版本docker用来连接tcp,不推荐配合wsl
  • 如果vscode使用wsl的docker取连接tcp地址

   # 创建bat文件,文件内容
   F:\\LxRunOffline.exe run -n ubuntu -c "export DOCKER_HOST=tcp://192.168.1.244:39012 && docker %1 %2 %3 %4 %5 %6 %7 %8 %9"

   # 设置vscode,docker.dockerPath的值为bat文件的位置,如:C:\Users\jcleng\Desktop\docker.bat
   # 然后就可以在右键:Attach Shell 了

  • shell配置

  # 配置一个shell,我用的工具是LxRunOffline,使用ubuntu的zsh(使用docker记得配置DOCKER_HOST)
  "terminal.integrated.profiles.windows": {
    "wsl_lxx": {
      "path": "F:\\LxRunOffline.exe",
      "args": [
        "run",
        "-n ubuntu",
        "-c /home/jcleng/.nix-profile/bin/zsh",
      ]
    }
  },