Expose docker deamon from wsl to windows - docker

With latest update for windows11 and wsl, now we are able to tu use systemd on wsl (yay)
So the first thing I've done was to enable it and install docker following those instuctions on my ubuntu 22.04 distro, and it works fine.
Second part of my evil plan was to expose docker daemon from wsl to windows and install docker-cli from windows too (I don't need desktop version)
So I made those changes to /lib/systemd/system/docker.service (add -H tcp://0.0.0.0:2375 to dockerd conf)
on windows host add DOCKER_HOST env
but if I try to run any docker cmd thst's what I get
Any suggestion? I'm missing something?

Related

Docker without docker dekstop. How to run Dockerfile

I want to run docker container on windows without docker desktop.
I dont know how it could work.
I installed Ubuntu on Windows (from Microsoft Store).
In Windows cmd i can write 'wsl' and then it brings me to Ubuntu cmd. In Ubuntu i installed Docker and its working.
Now I have project on Windows with Dockerfile. How can i run it ?
Because i have two systems Windows with my project and Linux with docker. What i have to do now to makes it works ?
Thanks
In your WSL navigate to your Dockerfile location. /mnt/c is the windows C: drive location inside the WSL. Build your Dockerfile with docker build. Run it with docker run. If the docker commands complain about the docker daemon not being reachable you need to start it with sudo service docker start.

How can I access wsl2 which is used by Docker desktop?

I want to transfer a Docker image from my Windows10 PC to another one, Fedora, using rsync. I can't use WSL, I need WSL2 as the compiler says:
ubu#DESKTOP-QL4RO3V:/mnt/c/Windows/system32$ docker images
The command 'docker' could not be found in this WSL 1 distro.
We recommend to convert this distro to WSL 2 and activate
the WSL integration in Docker Desktop settings.
For details about using Docker Desktop with WSL 2, visit:
https://docs.docker.com/go/wsl2/
But I think that as I have Docker desktop it is using WSL2:
But I don't know how to run the wsl2 Docker is using for my own.
PS C:\Users\antoi> wsl -l -v
NAME STATE VERSION
* Ubuntu Running 1
docker-desktop-data Running 2
docker-desktop Running 2
Docker Desktop images, containers, and volumes are stored in the special docker-desktop-data. As noted in this Super User question and my answer there, docker-desktop-data is not bootable (by design).
If you really had to get to the filesystem, I've documented a way to do so there. But in general, you should not need to do this.
Instead, use the normal docker commands (from WSL2, PowerShell, or CMD) to save the image to a tar file as documented in this answer:
docker save -o <image.tar> <image_name>
Then transfer the file using rsync or other means, and on the destination machine, import it via:
docker load -i <image.tar>
Again, that's from WSL2, PowerShell, or CMD. But in your case, the Ubuntu instance is WSL1. That won't work for Docker. You'll need to convert it to WSL2.
Just in case, I always recommend backing up your instance before converting it. From PowerShell:
wsl --export Ubuntu ubuntu_backup.tar
Then, once you have the backup:
wsl --set-version Ubuntu 2
wsl --set-default-version 2 # if desired
After conversion, you shouldn't see that error when running docker in Ubuntu.
Side note -- Docker Desktop "injects" the docker command into any WSL2 instance that you set in the "WSL Integration" tab in Settings. This should default to your "default" WSL2 instance, which (from your screenshot) is Ubuntu. The "real" docker command is inside docker-desktop, but it's linked into Ubuntu for you.
So by default, you should have all docker functionality directly in your Ubuntu instance. Neither docker-desktop nor docker-desktop-data are designed to be used directly by the end-user.
You can access docker desktop WSL using the following command
wsl -d docker-desktop

docker daemon can't running on ubuntu container

On my windows 11, I install Docker Desktop and ubuntu image.
On ubuntu container, I want install dapr,but dapr depends on docker
dapr init
⌛ Making the jump to hyperspace...
❌ could not connect to Docker. Docker may not be installed or running
so, then I install docker on ubuntu container, but the docker can't run (I have set export DOCKER_HOST=tcp://127.0.0.1:2375). how to solve this issue? Thanks!

Docker for Windows 10 how to access host machine

I am using docker for windows 10 for development. Before I used Docker Toolbox on windows 8. I am used to "tune" the host virtual machine in this case the MobyLinuxVM.
When I try to connect in hyper-v manager i get error cannot connect. When I try to docker-machine ls I get no docker machines. How can I possibly access the underlying machine on docker for windows 10?
Problems I want to solve are (aka why I want to connect):
Ubuntu apt-get doesnt work for me (I am behind proxy) get errors like E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/universe/source/Sources Cannot initiate the connection to 3128:80 (0.0.12.56). - connect (22: Invalid argument). On other hand Centos yum, curl,... works. http_proxy variables are set.
I want to turn off swap on the host.
update
Solved problem with apt-get by changin configuration of http proxy in docker settings from 1.2.3.4:1234 to http://1.2.3.4:1234/.
update 2
Worked around the problem by modifying /etc/init.d/automount in host and added swapoff -a.
I was able to access host MobyLinuxVM through container run with various privieleges.
First I ran container like that (note the double slash when mounting root filesystem. Single slash didnt work for me in powershell)
$ docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm -v //:/host alpine sh
after that when I got into container I just did
$ chroot /host
and then I could access all i needed. /etc/fstab or swapoff -a.

Not use docker-machine

I used docker with docker-machine ( can access container server by 192.168.99.100 ). I would like not to use docker-machine. so I can directly access my container by localhost (127.0.0.1). I shut down docker-machine (docker-machine stop) and tried to build image and container, but It said 'no daemon'. how should I completely shut down docker-machine and use local docker?
I think what you want is unset all docker-machine environment variables to use you host Docker daemon. This can be achieved with this command.
eval $(docker-machine env -u)
There are two different installs for docker on Mac. Both use a VM running Linux under the covers.
The older method includes docker toolbox and docker machine to manage the VM in virtualbox. When you use docker machine to stop this VM, the docker commands have no host to run on and will error out as you've seen.
The newer install uses xhyve to run the VM and various other tricks to make it appear seamless. This is a completely different install that you download and run from Docker, and it requires your Mac be at least version 10.10.3 with Yosemite.
See this install page for more details: https://store.docker.com/editions/community/docker-ce-desktop-mac?tab=description

Resources