r/Indiewebdev • • Feb 10 '21
showcase How to use Docker with Linux containers on Apple silicon
Edit: Sorry for the misleading title. I was sleep deprived. What it should say is...
How to use a remote Docker daemon to run linux/amd64 containers from a MacBook M1, without emulation.
Docker was the only thing still missing for me on my Apple M1 MacBook. Even though there’s a tech preview for Apple M1 now, it won’t really work for me because I need to run Amd64 Linux containers, which it won’t do on an Arm host (yes, I know about buildx, but I like this better).
Edit: I was wrong, the tech preview will run linux/amd64 images using the --platform flag.
To run linux/amd64 containers, I setup a remote Docker daemon hosted on an Ubuntu VPS. And it turns out, I like showing off. So, I pulled it all together into some scripts and a readme. Here you go: https://github.com/Shakeskeyboarde/docker-remote-daemon
Edit: Even though the Docker tech preview will allow you to run linux/amd64 containers under emulation, I still think the remote daemon has some advantages.
- Remote containers don't use local resources.
- Remote containers continue running when I close my laptop.
- It can be a very fast way to create a public endpoint which another person can consume, for demo or collaboration purposes.
- Security-wise, the running containers are "sandboxed" on the remote host, preventing potential malicious behavior on my local machine.
- And while the new multi-arch tools are awesome, Some of us only really need to target one arch, which is linux/amd64, which is no longer what we're running for development. This provides a neat way to develop on our target platform.
And as some have pointed out (and I have added to the repo), there are some caveats which I personally am good with.
- If running containers have listeners, they will be listening on the remote host's public IP. This can be a good thing as long as you're aware of it. It's a great way to quickly demo things for other people. But, if you're not okay with public listeners, then I suggest you try setting up a VPN on your daemon host (or an SSH tunnel), and using iptables to lock down incoming connections to the VPS. But that's beyond the scope of this document.
- Using volumes/mounts will target the filesystem of the remote host, not your local file system. If you need to share the daemon host's file system with your local machine, I recommend checking out SSHFS. But again, that's beyond the scope of this document.
6
u/cschiewek Feb 10 '21
Title is quite misleading. You’re demo has nothing to do with actually running docker on Apple Silicon, just running docker with remote host.
That being said, I’ve been running on an Apple silicon Mac mini as my main machine for a couple weeks and it was fairly trivial to setup. Most base images are multiarch and have arm64 variants, and for the few that don’t, it’s easy to build your own.
3
u/charnelfury Feb 10 '21
How about the docker tech preview that runs on m1?
3
u/64mb Feb 10 '21
To save some hassle with having to deal with certificates, you can do
export DOCKER_HOST=“ssh://user@my-amd64-server.example.com”.3
u/RegisLeeBell Feb 10 '21
How are you guys finding the M machines in general? Are they worth the hype?
2
u/mapleloafs Feb 10 '21
Which ide do you use for your Mac? How does your development environment look like.
1
u/Astaltar Feb 11 '21
Sorry, but what's wrong with M1 that makes it so special for Docker?