Tag: docker

  • Install Home Assistant Docker/Portainer

    Since Home Assistant now requires you to swap from Supervised to Docker or OS i figured i’d make a quick tutorial on creating a quick Docker tutorial on reinstalling it.

    Backing Up/Downloading Encryption Key

    First, we go to your Settings

    Home Assistant, click settings
    Right Arrow Blue: https://pixabay.com/vectors/arrow-left-pointing-previous-31182/

    Then Backups

    Home Assistant, click Backups

    Before you continue, make sure you have a new backup and download it to your computer so we can upload it later. If you’re using Home Assistant Cloud, you just have to make a new backup and upload it to the cloud if you want to restore from the cloud.

    Click Settings and History

    Home Assistant, click Settings and History
    Right Arrow Blue: https://pixabay.com/vectors/arrow-left-pointing-previous-31182/

    Download your Emergency Kit txt file

    Home Assistant, download Emergency Kit

    We have to make sure you have your emergency kit downloaded so we can use your encryption key when you restore from your backup.

    After the Emergency Kit is downloaded, go back.

    Right Arrow Blue: https://pixabay.com/vectors/arrow-left-pointing-previous-31182/

    Click Show Backups

    Now we go and download your latest backup.

    Click the three vertical dots

    Home Assistant,  download backup
    Right Arrow Blue: https://pixabay.com/vectors/arrow-left-pointing-previous-31182/

    Click on download.

    This will take a while if your backup is large.

    Home Assistant, download backup

    After that’s all done, we can continue on!

    While that is downloading, we should either create your compose file or set up Portainer.

    If you need to set up Docker, check this out!

    Compose File Creation

    Here is the basic Compose file for getting Home Assistant running in Docker.

    *Note* The official docs for installing Home Assistant in a Docker Container includes container_name: homeassistant above the line image: "ghcr.io/home-assistant/home-assistant:stable". Avoid container_name unless you have a specific need (legacy scripts, monitoring tools expecting a fixed name). Rely on the service name and Compose defaults for cleaner, more portable setups.

    services:
      homeassistant:
        image: "ghcr.io/home-assistant/home-assistant:stable"
        volumes:
          - /PATH_TO_YOUR_CONFIG:/config
          - /etc/localtime:/etc/localtime:ro
          - /run/dbus:/run/dbus:ro
        restart: unless-stopped
        privileged: true
        network_mode: host
    YAML

    services is where we tell Docker that we’re creating a container.

    homeassistant is the name of the container when accessed with the Docker command line and other related things like networking, etc..

    image: "ghcr.io/home-assistant/home-assistant:stable" tells Docker Compose that we want the latest stable image of Home Assistant.

    services:
      homeassistant:
        container_name: homeassistant
        image: "ghcr.io/home-assistant/home-assistant:stable"
    YAML

    Changing the config folder path

    Here is where we have to change /PATH_TO_YOUR_CONFIG to where you want to store your Home Assistant configuration files.

        volumes:
          - /PATH_TO_YOUR_CONFIG:/config
    YAML

    We have to create a folder like /home/hassio/home_assistant/ha_config, in my case, hassio is the username of this account. I created a folder home_assistant and then ha_config.

    I created two folders nearly named the same because I want to run some addons as well, so I put the config folder for each addon in home_assistant, then my Home Assistant configuration folder is ha_config.

    All you need to do is SSH into your device with something like Putty or CMD/Terminal. Log in as the user you want to manage the Home Assistant Docker setup with. In my case, it’s hassio. Then, create the folder or folders, as I did for my setup, or create a folder in your user’s home directory and call it good. It’s up to you what you want to do.

    Create a folder with:

    mkdir ha_config
    Bash

    Replacing ha_config with what you want to use, if you use a different name.

    Understanding the Configuration

        volumes:
          - /etc/localtime:/etc/localtime:ro
    YAML

    This line allows Home Assistant to read the time on your computer.
    Assuming it’s been set up already.

        volumes:
          - /run/dbus:/run/dbus:ro
    YAML

    This allows Home Assistant to communicate with the host’s system bus — e.g., to talk to system services (BlueZ Bluetooth, systemd, Avahi, some hardware/service discovery daemons) that expose APIs over D-Bus. Home Assistant uses this to access some integrations that expect a system D-Bus to be available on the host.

        restart: unless-stopped
        privileged: true
        network_mode: host
    YAML

    restart: unless-stopped tells Docker to restart the container automatically if it exits (crashes, is killed, or the daemon restarts).

    privileged: true grants the container nearly every capability the host kernel gives processes — roughly equivalent to giving the container full root-like access to the host.

    network_mode: host makes the container share the host’s network stack. Practically: the container has the host’s IP addresses and network interfaces. It does not get its own isolated network namespace. In this mode, you do not need ports: mappings — the container listens on the host interfaces directly, localhost inside the container == localhost on the host, service discovery via Docker networks (service-name DNS) does not apply for other containers — host networking bypasses those DNS aliases.

    Make sure you save the file, then we can continue!

    Setting up the Container in Portainer

    First, we have to navigate to the Portainer host. If you need help with setting up, check out this post!

    Next, we have to start creating a new container.

    We are going to be using the following details to input into Portainer.

    services:
      homeassistant:
        image: "ghcr.io/home-assistant/home-assistant:stable"
        volumes:
          - /PATH_TO_YOUR_CONFIG:/config
          - /etc/localtime:/etc/localtime:ro
          - /run/dbus:/run/dbus:ro
        restart: unless-stopped
        privileged: true
        network_mode: host
    YAML

    First, we navigate to the containers section and click on Create Container

    Then select New Container on the top right

    You should get a page like this, where we can put the name of the container from line #2 from above.

    Now we click on Advanced

    Paste the URL from the image section, copying between the quotes

    Set the Entrypoint to '/init' and the Logging Driver to json-file

    Set your volumes, copying everything from the volumes section from above. Replace the host /config section and optionally set the /backups folder if you want to set a backup location on your host

    Set your Network to Host

    Set your timezone and, optionally, the PUID and GUID to the user’s home folder that you’re putting the files in, so you don’t run into any folder/file permission issues

    Set your Restart Policy

    Here we set the Privileged Mode, and any Devices that you need to mount. Optionally, but recommended, set the Resources to a max of what I have set here.
    I have 5.840 Entities, 4,297 Sensors, 160 Integrations, and 103 Automations. I have no issues running Home Assistant with these restrictions.

    Now we can click Deploy to download the image and start the container!

    Check the logs of the container with the logs button:

    You will now see the current logs of Home Assistant, and it will tell you if anything is wrong. You can set the log’s lines higher if you need to and make sure to turn off auto refresh if you need to read anything, as it refreshes every few seconds, so you can see the latest entries. Don’t mind the red as one of my sensors in complaining.

    You should now be all set to use Home Assistant!

    Starting the Container with Docker Compose

    Now we should be ready to start up Home Assistant for the first time!

    All you need to do to start the container is type:

    # run with sudo if your user isn't a part of the docker group
    # change the .yaml file to the one that you created
    docker compose compose.yaml up -d
    Bash

    We can check the logs of Home Assistant with:

    # run with sudo if your user isn't a part of the docker group
    # replace homeassistant with the name of the service that you set in the compose file from before
    docker compose -f homeassistant
    Bash

    Assuming everything went well, you should be ready to configure Home Assistant itself!

    Here is a quick cheat sheet for Docker Compose!

    # remember to add sudo if your user isn't a part of the docker group!
    # bring up all services in foreground (attach)
    docker compose up
    
    # bring up in background (detached)
    docker compose up -d
    
    # rebuild images then up
    docker compose up -d --build
    
    # stop services (but keep containers)
    docker compose stop
    
    # start stopped services (existing containers)
    docker compose start
    
    # restart services
    docker compose restart
    
    # show running compose containers for the project
    docker compose ps
    
    # show logs (follow)
    docker compose logs -f
    # logs for a single service:
    docker compose logs -f web
    
    # execute a shell in a running container
    docker compose exec web /bin/bash
    # or if you need tty:
    docker compose exec -T web /bin/bash
    
    # run a one-off command (creates a temporary container using service definition)
    docker compose run --rm web bash
    
    # bring everything down (stop + remove containers, networks)
    docker compose down
    
    # remove stopped containers, networks, images not used by any service
    docker compose down --rmi all --volumes --remove-orphans
    
    # build images only
    docker compose build
    
    # pull images only
    docker compose pull
    Bash

    Have fun with the greatest home automation platform in the world(in my opinion)!

    If you need any support, feel free to leave a comment or message me on one of my socials! Just make sure to keep it relevant as I get a lot of scam messages and I don’t have a lot of time to waste on spam lol.

    I hope you have fun and have a great day!

  • Installing Docker on Debian

    Here’s a quick tutorial on installing Docker and Docker Compose V2 on Debian! This requires that your account has sudo access.

    First, we have to make sure that we have possible conflicting packages removed. Debian may ship older/unofficial packages that conflict with Docker’s official packages.

    sudo apt remove docker docker-engine docker.io containerd runc docker-compose docker-doc podman-docker
    Bash

    After that finishes, we can start installing Docker. Enter these line by line, minus the added comment(#) lines.

    sudo apt update
    sudo apt install -y ca-certificates curl gnupg lsb-release
    
    # Create keyring dir (if not exists) and add Docker GPG key
    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    
    # Add the Docker apt repo (uses your Debian codename)
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    # Apply changes to apt
    sudo apt update
    Bash

    Next, we will install Docker Engine, the CLI, containerd, Buildx, and the Docker Compose plugin (Compose V2).

    sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    Bash

    Then we start and enable Docker.

    sudo systemctl enable --now docker
    Bash

    This is optional, but it’s nice to have.

    We can add the current user to the Docker group, so we don’t have to run sudo all the time when we use Docker commands.

    sudo usermod -aG docker $USER
    Bash

    After adding yourself to the Docker group, you must re-login to apply the changes.

    Next, we can verify it’s working with the commands.

    docker version
    sudo docker run --rm hello-world
    Bash

    The first one shows the version of Docker that is installed, while the second one runs the hello-world container.

    As of writing this, my Docker version outputs something like this:
    Client:
    Version: 26.1.5+dfsg1
    API version: 1.45
    Go version: go1.24.4
    Git commit: a72d7cd
    Built: Wed Jul 30 19:37:00 2025
    OS/Arch: linux/amd64
    Context: default
    Server:
    Engine:
    Version: 26.1.5+dfsg1
    API version: 1.45 (minimum version 1.24)
    Go version: go1.24.4
    Git commit: 411e817
    Built: Wed Jul 30 19:37:00 2025
    OS/Arch: linux/amd64
    Experimental: false
    containerd:
    Version: 1.7.24~ds1
    GitCommit: 1.7.24~ds1-6+b4
    runc:
    Version: 1.1.15+ds1
    GitCommit: 1.1.15+ds1-2+b4
    docker-init:
    Version: 0.19.0
    GitCommit:

    docker compose version
    Bash

    This one will tell you what version of Docker Compose you have installed.

    As of writing this, my Docker Compose version outputs:
    Docker Compose version v2.40.3

  • Install Portainer on Debain

    Let’s get Portainer installed!

    You can either run these commands as ‘sudo’ or run ‘sudo -i’ to run these commands as root.

    All we need is at least SSH access and/or ftp access(to make it easier for file editing), but that is optional if you just want to quickly get this installed.

    Quick Rundown: All we need to do is SSH into the device we want to install Portainer on, configure the ‘compose.yaml’ file and run it.

    First, SSH into the device with your tool of choice. Ex. Putty, CMD, Terminal, etc.

    In my case, I use nano:

    Edit compose file with nano

    Paste this for the base config:

    services:
      portainer:
        image: portainer/portainer-ce:latest
        container_name: portainer
        restart: always
        ports:
          - "9443:9443"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - /home/hassio/home_assistant/portainer_data:/data
        environment:
          - TZ=change_me
    YAML

    So we have:

    services:
      portainer:
        image: portainer/portainer-ce:latest
        container_name: portainer
    YAML

    Which defines the name of the container to Docker ‘portainer’, you will use this to modify the container later.

    image: portainer/portainer-ce:latest
    YAML

    Tells Docker what image to run. ‘portainer/portainer-ce‘ is Portainer’s Community Edition, ‘:latest’ is the tag, it will pull the newest latest tag on startup.

    restart: always
    YAML

    This is the Docker restart policy. If the container stops (or the host reboots), Docker will automatically try to start it.

        ports:
          - "9443:9443"
    YAML

    Maps host port 9443 to container port 9443. Portainer uses 9443 for the HTTPS web UI by default. After it starts, you’ll access Portainer at https://<host-ip>:9443.

        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
    YAML

    This binds the Docker socket into the container. This is what gives Portainer the ability to control Docker (list containers, start/stop, create volumes, etc.). VERY powerful: any process that can talk to the Docker socket can control the Docker daemon (and therefore the host).

        volumes:
          - /home/hassio/home_assistant/portainer_data:/data
    YAML

    A host directory mounted into the container’s /data — used by Portainer to store its state (users, settings, DB). This ensures data persists after container upgrades.

    Make sure to create a folder so Portainer can store its data. In my case, I put it under my users folder ‘/home/hassio/home_assistant/portainer_data’, but you would probably want to do something like ‘/home/’your username’/portainer_data’ instead. If you copied the file, make sure to change ‘/home/hassio/home_assistant/portainer_data’ to what suits your needs.

        environment:
          - TZ=change_me
    YAML

    This sets the timezone inside the container so logs and scheduled tasks use that timezone. Cosmetic but helpful. Make sure to change the timezone name or delete it.

    All you have to do next is change the Timezone, based on the name you find here.

    You can see my post on how to set the timezone here if you need more info on that.

    sudo docker compose -f compose.yaml config
    Bash

    All you need to do next is run that command, replacing ‘compose.yaml’ with your filename, to validate your Compose file.

    sudo docker compose -f compose.yaml up -d
    Bash

    That brings the container up.

    sudo docker compose ps
    Bash

    You can see the status of your running containers with that.

    sudo docker ps --filter name=portainer
    Bash

    Or use this one to specifically see the status of Portainer if you have multiple containers running. Make sure to change ‘portainer’ to the name that was used in the configuration file.

    sudo docker compose logs -f portainer
    Bash

    With this one, you can see the log file.

    Now your Portainer container should be up and running!

    Navigate to ‘https://<host-ip>:9443’, replacing the port number if you changed it in the compose file and replacing ‘<host-ip>’ with the device’s actual IP address.

    Make sure to create a strong password, as anyone who has it will be able to change your containers and potentially do malicious things.

    Here is the Portainer Installation Documentation if you wish to view it.

    I hope this helped you out! Have a great day and have fun building containers!

    Leave a comment if you need any help. I’ll be glad to support you!

  • Docker Compose Set Timezone

    I’m going to assume you have SSH and/or ftp access to modify the ‘compose.yaml’ file that you intend to modify.

    All we need to do is add the ‘TZ’ variable to the environment section with your timezone name that you can get from Wikipedia here, like so.

    services:
      service_name:
        environment:
          - TZ=America/Edmonton
    YAML

    Portainer

    All you have to do for portainer is create a new environment variable called TZ with the value of your timezone, like so:

    Click Deploy just above the advanced section, then your container will be recreated with the new environment variable!

    Compose More Detailed Version

    Let’s edit the compose file:

    nano compose.yaml
    Bash

    or…

    sudo nano compose.yaml
    Bash

    Depending on what your permission for your file is.

    Edit your compose file:

    sudo nano compose.yaml

    Go to the Wikipedia page here and look up your Timezone in the table.

    Wikipedia Timezone Table - Timezone Identifier
    Nano Docker Compose edit file

    Copy/Paste the ‘TZ Identifier’ and add it to your Docker Compose file like so. If you don’t have the ‘environment’ section, you can copy and paste this.

        environment:
          - TZ=
    YAML

    Make sure you have 4 spaces from the start of the line and 2 spaces from the start of the ‘environment’ section on the next line for the ‘- TZ=’ section(6 from the beginning of the line). YAML is space-sensitive, so it will fail to compile if the spaces are wrong.

    You should validate the file to make sure you don’t get any errors. All you need to do is type.

    sudo docker compose -f compose.yaml config
    Bash

    In this command, we use ‘sudo docker compose -f’, which, in this case, the ‘-f’ tells Docker Compose that we are dealing with Compose configuration files. ‘compose.yaml’ is the name of the compose file in my case. Replace it with the name of your file. Finally, ‘config’ is the command that tells it that we will parse, resolve and render the compose file.

    You should get the output of the file if it validated correctly:

    Docker Compose validate config

    Now you can bring the container up with:

    Replace the ‘compose.yaml’ with your file name.

    sudo docker compose -f compose.yaml up -d
    Bash