Reputation: 567
I have Windows 10 and had Docker Desktop installed. After they changed terms of commercial use I decided to remove Docker Desktop installation and use just docker engine itself (as I didn't use GUI). I've installed docker
on Ubuntu under WSL 2 and it works fine:
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:~$
Right now I want to allow my JetBrains IDE to connect to Docker Engine. I have the following options:
So what is the best way to configure connection? Can I somehow "create a link" to pipe to use Docker for Windows
option? Seems like it just tries to connect to npipe:////./pipe/docker_engine
. Or I can expose TCP/SSH ports.
I am new to configuring docker so please explain which option I can use.
Upvotes: 20
Views: 10297
Reputation: 2231
I had issues with more recent versions of Docker as they do not allow double-configurations from the service entry point and the daemon.json.
Here is my solution that seems to work great:
Add a config override to also expose the tcp socket:
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/override.conf > /dev/null <<EOT
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
EOT
Note: You can copy the line from /lib/systemd/system/docker.service
and just add -H tcp://0.0.0.0:2375
at the end.
Reload and Restart the Docker daemon:
sudo systemctl daemon-reload
sudo systemctl restart docker
Set the environment variable in Windows to the correct endpoint:
DOCKER_HOST=tcp://localhost:2375
Install a Docker CLI on Windows, for example with Scoop:
scoop install docker
scoop install docker-buildx
Run any Docker command in Windows:
docker ps
Note: If you want to mount a volume from Windows, this does not work directly as the Docker "context" is the one from WSL, so you need to use paths from WSL. So if you want to mount the folder c:\foo\bar
into the container, you can use a command like (note the double //!):
docker run --rm -it -v //mnt/c/foo/bar://bar debian
Upvotes: 3
Reputation: 311
Disclaimer: not an expert, just had the exact same problem and solved it like this.
By default the docker daemon is started, exposed only on an unix socket.
As far as i can tell there is no way to directly specify that unix socket in intellij, instead some workaround would be required on the windows part, i have no idea how much work this would be.
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
).
Once setup, you may once again configure intellij to interact with the docker daemon via tcp.
Please note the involved security concerns of exposing your docker daemon to a network.
docker run hello-world
)/etc/docker/daemon.json
{ "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"] }
sudo service docker restart
used:
wsl 2, ubuntu 20.04, windows 10.0.19043
docker installation as per: https://docs.docker.com/engine/install/ubuntu/
caveat: systemd does not currently, fully, work out of the box on wsl2 therefor some options may not be available.
This new workflow: "docker in ubuntu" may drastically vary from your previous experience due to the way wsl2 handles file transfer between windows and wsl2.
You might want to consider moving all files to ubuntu or running docker on windows through some means.
Upvotes: 15