This guide will help you set up Home Assistant to run as a docker container on your Raspberry Pi

Prerequisites

  • Raspberry Pi with a running Raspbian OS
  • SSH connection enabled

To do this you can check Raspberry Pi Setup

Installing Docker

First of all make sure that the system runs the latest version of the software.

  • sudo apt-get update && sudo apt-get upgrade

Install Docker

  • curl -sSL https://get.docker.com | sh

Add a Non-Root User to the Docker Group

By default, only users who have administrative privileges (root users) can run containers. If you are not logged in as the root, one option is to use the sudo prefix.

  • sudo usermod -aG docker [user_name]

Check it worked by running:

  • groups ${USER}

Reboot the Raspberry Pi to let the changes take effect.

Installing Docker Compose

Docker-Compose usually gets installed using pip3. For that, we need to have python3 and pip3 installed. If you don’t have it installed, you can run the following commands:

  • sudo apt-get install libffi-dev libssl-dev
  • sudo apt install python3-dev
  • sudo apt-get install -y python3 python3-pip

Once python3 and pip3 are installed, we can install Docker-Compose using the following command:

  • sudo pip3 install docker-compose

Enable the Docker system service to start your containers on boot

This is a very nice and important addition. With the following command you can configure your Raspberry Pi to automatically run the Docker system service, whenever it boots up.

  • sudo systemctl enable docker

With this in place, containers with a restart policy set to always or unless-stopped will be re-started automatically after a reboot.

Setting up Home Assistant

Now that we have all of our prerequirements completed we can start setting up Home Assistant

Setting up or machine

First we will need to create a directory for Home Assistant. Navigate to where you want your Home Assistant files to be saved and create a directory.

  • mkdir home-assistant

Then we need to create a directory in home-assistant to house our configs

  • mkdir home-assistant/config

Creating docker compose

Now we have our directorys set up we can create our docker compose file. Inside the home-assistant directory create a file called docker-compose.yaml that looks like this

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/raspberrypi4-homeassistant:stable"
    volumes:
      - {PATH TO CONFIG DIR}:/config 
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0

Running the container

Spin up the docker container by running

  • docker-compose up -d

Once the docker container is up and running you can access Home Assistant by going to http://{YourIP:8123}

The first time you access Home Assistant you will go through the onboarding process and set up your initial configs. All of these configs will be saved in your home-assistant/config folder and will persist through shutdowns and restarts

Stopping the container

You can bring down the container by running

  • docker-compose down