/docker-remote-daemon

Bash setup scripts for provisioning and connecting to a remote Docker daemon.

Primary LanguageShell

Docker on Apple (ARM64) using a remote daemon on Ubuntu (AMD64)

This repository contains instructions and setup scripts for installing the Docker client locally (Apple), the Docker daemon remotely (Ubuntu), and configuring them to work together.

Q: Why would you want to do this?

A: Because support for Docker on Apple silicon is still progressing. Even when Docker becomes Apple native, it will still only run Arm64 containers on Apple silicon, and building will require emulation (buildx). Running the daemon remotely on an Amd64 Linux host allows me to continue running Amd64 images right now, and building does not require any additional configuration or emulation. I can run and build on the same platform the images will be deployed to.

Caveats

  • If running containers have listeners, they will be listening on the daemon 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, 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 daemon 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.

 

Let's begin.

Follow these three (easy-ish) steps to get Docker working on your Apple silicon.

Step 1: Acquire an Ubuntu (20.04 LTS) instance

You will need to be able to SSH into it as the root user.

I highly recommend creating a Kamatera Type A (availability) VPS instance with at least 1GB of RAM and 20GB of storage. It's cheap (but not free), easy, and works great for running a Docker daemon.

Step 2: Install the Docker client

Run the setup-local-docker-client.sh script by pasting the following command in a terminal.

bash <(curl -sL https://raw.githubusercontent.com/Shakeskeyboarde/docker-remote/main/setup-local-docker-client.sh)

This script will download a tarball of the latest stable Docker client, and extract the docker binary to your /usr/local/bin directory. This will NOT install the Docker daemon locally. You can run this script again at anytime to upgrade or re-install the Docker client.

When it's done, you should be able to run the following command:

docker --version

Step 3: Provision the Docker daemon

Run the setup-remote-docker-daemon.ts script by pasting the following command in a terminal (I'm sensing a pattern).

bash <(curl -sL https://raw.githubusercontent.com/Shakeskeyboarde/docker-remote/main/setup-remote-docker-daemon.sh)

This script will...

  1. Ask you for the SSH endpoint (eg. root@1.2.3.4) of your Ubuntu host, and you might have to enter the user's password once.
  2. Install your public key on the remote, so that you don't need to enter a password repeatedly.
  3. Install the Docker daemon on the remote.
  4. Create a local Docker context called remote.
    • You can add export DOCKER_CONTEXT=remote to your .zshrc and/or .bashrc file to make it the default context.

You can run this script again at any time to upgrade or re-provision the Docker daemon, or to generate new certs.

Step 4: Profit.

That's it. You can now use docker commands the same way you always have.