Intellij series IDE / VSCode connects to Docker Engine remotely (the key point is that windows uses docker clinet to connect to docker engine remotely)

Intellj / VSCode does not require any configuration to connect to the local Docker, and it can be directly connected by default, so it will not be described here.

Here's how to connect Docker Engine remotely with each IDE:

1. Docker Engine configuration

By default, Docker only listens to local Unix connections and cannot be accessed remotely. Therefore, you first need to let Docker Engine listen to the TCP remote port. Modify /etc/docker/daemon.jsonthe hostsparameters:

{
    "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"]
    "oom-score-adjust": -1000,
    "log-driver": "json-file",
    "log-opts": {
      "max-size": "50m",
      "max-file": "1"
    },
    "max-concurrent-downloads": 10,
    "max-concurrent-uploads": 10,
    "insecure-registries" : ["harbor.internal.xxx.com"],
    "registry-mirrors": [
      "https://dockerhub.azk8s.cn",
      "https://hub-mirror.c.163.com"
    ],
    "storage-driver": "overlay2",
    "storage-opts": [
      "overlay2.override_kernel_check=true"
    ]
}

The main line is the first hostsparameter, the other parameters are mainly mirror some warehouses, configuration log size restrictions, see DevOps-Docker

Changing for the better after systemctl restart dockerthe restart docker engine.

Second, IDE configuration

1. Intellij series IDE: Idea / Pycharm / Goland / Rider, etc.

The full range of IDEs comes with a Docker plugin, which uses java's docker sdk to interact with Docker Engine. There is no need to install docker / docker-compose client separately. You
only need to give a remote api and certifact certificate (for authentication).

2. VSCode configuration

According VSCode Docs - Container Advanced - Host connect remote Docker , VSCode of Container plug-in requires the machine to be installed docker-clientand docker-compose.

Installation methods of the above two clients:

  1. Linux: Refer to Rancher-Docker installation , just remove the docker-engine installation.
  2. Windows: Use chocolaty installed choco install docker-cli docker-composeto
    • Choco's docker-cli source: StefanScherer / docker-cli-builder , is a third-party compiled version, unofficial.
    • choco's docker-compose source: in docker-compose-github release , the official package.
    • docker-composeIt is written in pure python, and therefore can also pip install docker-composebe installed.
    • There is no need to install the bloated docker-desktop, it is not compatible with vmware / virtualbox, and it only supports windows 10 pro and above, which is a waste. . .

After installing the client, set the Docker remote address DOCKER_HOST through environment variables:

# Linux 临时设置环境变量
export DOCKER_HOST='tcp://X.X.X.X:2375'

# Windows Powershell
$env:DOCKER_HOST = 'tcp://X.X.X.X:2375'  # 临时设置环境变量
[Environment]::SetEnvironmentVariable("DOCKER_HOST", "tcp://X.X.X.X:2375", "User")  # 修改当前用户的环境变量,只对新进程有效

Then restart VSCode, click the Docker plugin on the left, you can find that the plugin has been connected haha.

In addition, enter directly in powershell docker ps, you will find that the docker command can also be used normally. Very comfortable, much more comfortable than using windows-docker-desktop.

I currently open a vmware virtual machine locally, and then the windows machine connects to the docker engine in the virtual machine through the above configuration.

Guess you like

Origin www.cnblogs.com/kirito-c/p/12677364.html