DEV Community

Jairo FernĂĄndez
Jairo FernĂĄndez

Posted on • Updated on

Docker is destroying my machine! đŸ’„

Other possible titles for this post

“RTFM, oh boy
”
Buy a new laptop

Saving Private Ryan, where are you daemon.json?

I need to reconsider the use of Docker on my Mac M1 Pro. With a small disk and 1000 programs 😅, everything is fine at least until I start Docker Desktop. I use a lot of images and experiments that I never finish because I’m a lazy person. I was looking for some solution because my machine is crying all the time, and I feel like a loser deleting files, running docker system prune, and deleting my 1 million node modules from unfinished projects


I have an old machine that I just use to do some experiments or run Windows for specific tasks or problems. That machine has Ubuntu and Windows as a dual boot. Yes, it’s a Frankenstein, and I feel nostalgic about Ubuntu.

— Sheldon: “Oh, Ubuntu!”

Image description

Ok, give me the đŸ’© solution.

I installed Docker on Ubuntu, allowed remote connection, and overrode the Docker client host to point to my old machine, and voila!

Or at least, I thought it was really easy to do. I checked the internet and ChatGPT told me to edit /etc/docker/daemon.json on my Ubuntu machine and just put:

{
  "hosts": [
    "unix:///var/run/docker.sock",
    "tcp://0.0.0.0:2376"
  ]
}
Enter fullscreen mode Exit fullscreen mode

Easy peasy


Image description

No, that broke my Docker on Ubuntu (24.04 LTS).

After a couple of hours and going through a lot of tutorials, I found the documentation!! (Yes, RTFM) https://docs.docker.com/config/daemon/remote-access/ and finally understood why I couldn’t find the file. It was a misunderstanding of how Docker runs on the OS and the changes of Ubuntu to systemd.

For systemd we need to edit the service with sudo systemctl edit docker.service, as the documentation said, but, oh surprise, it didn’t work for me


So, what happened was I needed to edit the service file directly:

sudo nano /lib/systemd/system/docker.service
Enter fullscreen mode Exit fullscreen mode

And I commented out the lines containing ExecStart below [Service], and added these lines:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
Enter fullscreen mode Exit fullscreen mode

I restarted the service with:

sudo systemctl daemon-reload
sudo systemctl restart docker.service
Enter fullscreen mode Exit fullscreen mode

You need to confirm if port 2375 is accessible on your local network (this is another story; on my machine, it was available by default).

For now, that’s all on Ubuntu. Now, on the Mac, Docker doesn’t start on login, so when I run docker ps on the terminal, you’ll see:

docker ps      
Cannot connect to the Docker daemon at unix:///Users/your_user/.docker/run/docker.sock. Is the docker daemon running?
Enter fullscreen mode Exit fullscreen mode

And that’s ok. Now for the magic:

export DOCKER_HOST=tcp://<UBUNTU_LOCAL_IP>:2375
Enter fullscreen mode Exit fullscreen mode

Where UBUNTU_LOCAL_IP is the IP of your Ubuntu machine on the same network. Now, if you are on the same network:

docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
Enter fullscreen mode Exit fullscreen mode

And that’s it! Enjoy! 🎉

Please consider the security consequences of using this over your local network.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.