My Docker Stack

I think it’s the NUC7i3BNK. I will have to check tonight.

A. I don’t want that automated. I want to know when I am updating, and control my updates.
B. My internet is crap. I have to plan my updates around times where my wife and son are not using the internet.

I don’t need SAMBA on the host machine at all. I have no need for it. I automate my backups with restic going to my NAS, and I have my HASS configs all syncing to my desktop and NAS using syncthing. I have zero reason to touch the docker host, except for when I want to run updates.

I’ll have to check out sync thing. I keep meaning to but haven’t have time. Do you know if it can sync to say Amazon S3?

There’s a bunch of packages listed here https://www.home-assistant.io/hassio/installation/ that have to be available for Hassio on debian/ubuntu… Did I use the wrong word saying they were dependencies instead of packages? I’m clueless as I alluded to before and just follow the docs…

Have any of you played with this before? https://nickbusey.gitlab.io/HomelabOS/

1 Like

So I just created a docker-compose.yml file with the following:

version: '3'
services:
  portainer:
    container_name: portainer
    image: portainer/portainer
    volumes:
      - portainer_data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "9000:9000"
volumes:
  portainer_data:

This is basically right off the portainer site.

When I set portainer up, following the instructions I did this:
docker volume create portainer_data

Then I did this to install it:
docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

This did create everything under /var/lib/docker/volumes/portainer_data/_data

I then rebooted but portainer didn’t start.

I used the docker-compose up -d

and it created another bloody container???
and yep - the original container is there stopped and there’s a new container!!
The new one also has a stack name???

myusername_portainer_data

Why did it do that? What is wrong in my compose file? how do I get it to run compose automatically when docker starts?

Hi David

using the docker run command the --restart always is missing

sudo docker run -d -p 9000:9000 --restart always -v /var/run/docker.sock:/var/run/docker.sock --name portainer -v /var/docker/portainer:/data portainer/portainer

same for the compose, you need to add
restart: always

Also add the followuing in the compose to give the container a name
container_name: “portainer or whatever you wish”

OK I have the container name there and I’ll try adding the restart: always.

How do I make docker-compose start on boot-up?

As I have used the run with restart always already and it’s working quite well now - do I just delete the container and then let docker-compose start them all up again?

Or to put it another way, if a container is already restarting on boot, how do I back that out and let docker-compose take care of it all again.

I also had a bizarre issue getting sonarr to run as Python apparently was using port 8989 for itself. I changed the port for sonarr but it wouldn’t start until I found out the ini file for sonarr had it pointing to 8989. Changed that and it’s working.

Gotta say docker is making things so much easier to get going!

in the docker compose, for each container add restart: always to it
heres mine for mqtt

mqtt:
image: eclipse-mosquitto:latest
container_name: “mqtt”
restart: always
ports:
- “1883:1883”
- “9001:9001”
volumes:
- /srv/docker/mqtt/data:/mosquitto/data
- /srv/docker/mqtt/config:/mosquitto/config
- /srv/docker/mqtt/log:/mosquitto/log
network_mode: “host”

compose on boot-up
it’s in this post

Have been messing around with docker for a bit and am liking it very much. The speed at which you can remove and rebuild a container is great.

Mapping the volumes takes a bit of setup but I setup a test to see how passing my lets encrypt certificate over would go and it works great. The config files are easy to edit this way and I was surprised to see that the volume works both ways, nice to have the log available!

One downside is samba isn’t in the standard HA container and that means that some of my commands for shutting down computers don’t work.

Hoping to test moving my zwave over tonight and if that goes well Ill make the switch.

I love how lightweight Docker is. Coming from ESXi and virtual machines its nice not to have to set aside RAM that may not be getting used. I think I was using 182 MB with no containers running and only 256 MB with HA up and running.

Is this my mapped volumes folder? Is that what I would backup?
var/lib/docker/volumes

I also have a config folder /home/docker/config where my sonarr config and other stuff seems to live.

So if I’m backing up my docker config files do I backup the volumes and the config and docker-compose.yml? Is that all?

Is it possible to update an image via Portainer? Is this done simply by pulling the image again? Then would I restart the container to apply the image? If I can do this then it doesn’t seem to make sense to use a docker-compose file as I’ll never need the command line normally and all my containers currently start automatically…

There are breaking changes on almost every update and chances are that they might affect me. I don’t like the idea of my HA running along fine and then suddenly it stops working for no apparent reason. At least if I update it manually I can look at the breaking changes first and decide to update or not and know what I need to fix to get things running again.

That’s also the biggest reason I decided against running docker-compose. It’s too coarse grained for my preferences.

2 Likes

Here is my Portainer docker command:

sudo docker run --name portainer -d -p 9001:9000 --restart=unless-stopped -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer

I use restart=unless-stopped for my containers because I don’t want them trying to automatically keep trying to restart if I have stopped them for some reason.

It’s very easy to update using Portainer.

All you do is click on the container name in the Portainer view then on the next page that opens up you’ll see a menu item that says “recreate”. That command will pull the new image if it’s available and restart the container using the new image.

For any data you wish to backup you will save the data in the folders on the host that you are pointing your docker containers to.

For example, to save the HA config information using the following volume designation:

/home/finity/docker/hass-config:/config

Then I would backup all of the files/folders in the “/home/finity/docker/hass-config” directory on the host machine.

You would do the same thing for any data you want to save. Just backup the info in the directories defined on the left side of the “:”. Volumes were the hardest part of Docker for me to wrap my head around.

As far as ports go you can designate pretty much any port on the host to correspond to any port in the container. The default port for Portainer was 9000 but port 9000 was being used for something else so I just told Docker to map port 9001 on the host to port 9000 in the container. As far as Portainer is concerned it thinks it’s still using port 9000.

1 Like

you can ssh from the HA container into the host or any other system in your network and shutdown computers etc.

You know they will ask how to do it…

Just go ahead and post the link to your procedure. Don’t be modest! :smile:

1 Like

All good except for this bit…

In this compose file:

mqtt:
image: eclipse-mosquitto:latest
container_name: “mqtt”
restart: always
ports:
- “1883:1883”
- “9001:9001”
volumes:
- /srv/docker/mqtt/data:/mosquitto/data
- /srv/docker/mqtt/config:/mosquitto/config
- /srv/docker/mqtt/log:/mosquitto/log
network_mode: “host”

from above by @aidbish

Would this mean I need to backup
/srv/docker/mqtt/data
/srv/docker/mqtt/config
/srv/docker/mqtt/log

Also, if I stop my container in portainer, it does not seem to restart it automatically even though my command line has restart-always in it. I assume that if I restarted the NUC it probably would restart automatically but either way it seems to be working pretty damn well for now…

I cant find the original post, so here’s a re-run

SSH From HA Docker into other devices – HA upgrade example.

1-Need to modify the host user priveleges to skip typing your password with sudo

sudo visudo

hostuser ALL=(ALL) NOPASSWD:ALL

2-Mount this volume in HA container to preserve the sshkey generated from the HA container and used to execute shell commands. Key will then persist through reboot or upgrades.

-v /home/hass/docker/sshkey/.ssh:/root/.ssh

"/home/hass/docker/sshkey/.ssh" needs to be your own path

i.e

run docker:

sudo docker run -tid --name="homeassistant" --restart=always -v /home/hass/docker/homeassistant:/config -v /etc/localtime:/etc/localtime:ro -v /etc/letsencrypt:/certs -v /home/hass/docker/sshkey/.ssh:/root/.ssh --net=host --privileged --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/tty1:/dev/tty1 homeassistant/home-assistant

or docker-compose:

homeassistant:

container_name: homeassistant

image: homeassistant/home-assistant

restart: unless-stopped

network_mode: host

privileged: true

volumes:

- /home/hass/docker/homeassistant:/config

- /etc/localtime:/etc/localtime:ro

- /etc/letsencrypt:/certs

- /home/hass/docker/sshkey/.ssh:/root/.ssh

devices:

- /dev/ttyACM0:/dev/ttyACM0

- /dev/tty1:/dev/tty1

depends_on:

- mysql

- mqtt

- zoneminder

- configurator

- appdaemon

3-login to container via portainer or sudo docker exec -it <container_id> /bin/bash/

4-generate sshkey. - https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2

ssh-keygen -t rsa (press enter, enter, enter)

5-copy the sshkey to your host

ssh-copy-id [email protected] (type password when prompted)

6-upgrade script:

script:

update_home_assistant:

alias: Update Home Assistant

sequence:

- service: shell_command.update_hass

shell_command:

"if using run"

update_hass: ssh -l hostuser 192.168.x.x "sudo docker run -tid --name="homeassistant" --restart=always -v /home/hass/docker/homeassistant:/config -v /etc/localtime:/etc/localtime:ro -v /etc/letsencrypt:/certs -v /home/hass/docker/sshkey/.ssh:/root/.ssh --net=host --privileged --device /dev/ttyACM0:/dev/ttyACM0 --device /dev/tty1:/dev/tty1 homeassistant/home-assistant"

"if using docker-compose"

update_hass: ssh -l hostuser 192.168.x.x "sudo docker pull homeassistant/home-assistant:latest && cd ~/docker/homeassistant/templates && sudo docker-compose up -d"

"~/docker/homeassistant/templates -- this my directory for my docker-compose.yam"

this is my compose for mqtt

  mqtt:
    container_name: mqtt
    image: eclipse-mosquitto
    restart: unless-stopped
    volumes:
    - /srv/docker/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf
    - /srv/docker/mosquitto/config/passwd:/mosquitto/config/passwd
    - /srv/docker/mosquitto/log:/mosquitto/log
    - /srv/docker/mosquitto/data:/mosquitto/data
    - /etc/localtime:/etc/localtime:ro
    environment:
    - PGID=1000
    - PUID=1000
    ports:
    - "1883:1883"
    - "9001:9001"

My understanding is that you either expose ports or use network_mode: host. Not both

It’s just an example from higher up in the thread. I’m more interested in making sure I’m backing up the right things (volumes)

The way i posted it’s the correct way to back up and ensure it runs. this is from the eclipse docker hub