Skip to main content

Setup on Hetzner Cloud

Flatcar Linux is a lightweight Linux distribution, which is optimised for hosting Docker containers (and nothing else). Hetzner currently does not support installing Flatcar Linux directly from the web UI, but it can be installed with the following instructions.

Overview

  1. Create a new cloud server in Hetzner's UI. The OS or SSH keys do not matter and will be deleted.
  2. Restart the server into the rescue OS (see Hetzner's docs)
  3. Prepare the Ignition configuration file locally, and upload it to the server
  4. Run the installation script on the server

The first two steps are not documented here.

Step 3: Prepare the Ignition configuration

Paste the following content into a local file named config.yaml. Then update the SSH key with your own key.

config.yaml
variant: flatcar
version: 1.0.0
passwd:
users:
- name: core
ssh_authorized_keys:
- ssh-ed25519 AAA...2X4
storage:
files:
- path: /etc/flatcar/update.conf
overwrite: true
contents:
inline: |
REBOOT_STRATEGY=reboot
LOCKSMITHD_REBOOT_WINDOW_START=05:00
LOCKSMITHD_REBOOT_WINDOW_LENGTH=1h
mode: 0420
- path: /etc/modprobe.d/blacklist.conf
mode: 0644
contents:
inline: |
blacklist usb-storage

What this configuration does:

  • It adds your SSH key to the default user (core). The core user already has access to sudo (without a password) and to Docker.
  • It configures a reboot window from 05:00 to 06:00 (UTC). Without this, the server would reboot immediately when an update is available.
  • It disables the USB kernel module, since the server is not going to use any USB devices.

Next, run the following command locally. This will produce an ignition.json file that is used during the installation of Flatcar Linux.

docker run --rm -i quay.io/coreos/butane:latest < config.yaml > ignition.json

Connect to the rescue OS over SSH. Copy that file to the server, with the same filename.

Step 4: Run the installation script

On the rescue OS, run the following set of commands. You can also find the latest commands in Flatcar's article about Hetzner.

If you want to create a snapshot of your new server (e.g. to use it as a template for future servers), do so before booting the installed server, i.e. shut the server down instead of rebooting. This way, the machine ID is generated differently for each server. (And the snapshot stays quite small.)

apt update
apt -y install gawk
curl -fsSLO --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://raw.githubusercontent.com/flatcar/init/flatcar-master/bin/flatcar-install
chmod +x flatcar-install
./flatcar-install -s -i ignition.json
shutdown -r +1

Next steps

I recommend to install Portainer next, for easy managing of Docker containers and services.

The other stacks listed on this website could also be useful (e.g. Traefik).