Getting started with docker.

patrick123

Expert Member
Joined
Apr 10, 2005
Messages
2,894
Eventually we tend to move from the Raspi setup or simply jump in the deep end with an old computer.
Here, I hope to assist you guys starting a setup without having to search all over to get up and going.
BTW I went the Home Assistant route and not the Hassio docker.

These are the most important to get going.

My OS: Centos 7.7


Mosquitto:
Bash:
mkdir -p /home/shared/docker/mqtt/config
mkdir -p /home/shared/docker/mqtt/log
mkdir -p /home/shared/docker/mqtt/data


docker run --name mqtt --restart=always -p 1883:1883 -p 9001:9001 -tid \
  -e TZ=Africa/Johannesburg \
  -v /home/shared/docker/mqtt/config:/mosquitto/config:ro \
  -v /home/shared/docker/mqtt/log:/mosquitto/log \
  -v /home/shared/docker/mqtt/data/:/mosquitto/data/ eclipse-mosquitto

Linking Mosquitto to the Hisense TV MQTT server:
mosquitto.conf:
Code:
port 1883

persistence false
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log

#################################################
#
#           BRIDGE SETUP
#
#################################################
connection hisense
address 192.168.x.x:36669
topic # both
remote_username hisenseservice
remote_password multimqttservice
clientid HomeAssistant
try_private false
start_type automatic
cleansession true

MySQL/Mariadb:
Bash:
mkdir -p /home/shared/docker/mysql/database

docker run -d \
--name="mysql" \
--net=mysql-network \
-e TZ=Africa/Johannesburg \
-e MYSQL_ROOT_PASSWORD=MyPassword \
-v /home/shared/docker/mysql/database:/var/lib/mysql \
-p 3306:3306 mariadb

PHPMyAdmin :
Bash:
docker run --name phpmyadmin \
  --net=mysql-network \
  -e MYSQL_ROOT_PASSWORD=MyPassword \
  -e PMA_HOST="mysql" \
  -e PMA_PORT=3306 \
  -p 8080:80 \
  -d phpmyadmin/phpmyadmin

Home Assistant:
Bash:
mkdir -p /home/shared/docker/homeassistant/config

docker run --init -d --name="home-assistant" \
  -e TZ=Africa/Johannesburg \
  -v /home/shared/docker/homeassistant/config:/config \
  --restart always \
  --net=host homeassistant/home-assistant:stable

NodeRed:
Bash:
mkdir -p /home/shared/docker/node-red-data

docker run -d \
-p 1880:1880 \
--restart on-failure \
-e TZ=Africa/Johannesburg \
-v /etc/localtime:/etc/localtime:ro \
-v /home/shared/docker/node-red-data:/data \
--name mynodered \
nodered/node-red
 
Last edited:
  • Like
Reactions: OCP

patrick123

Expert Member
Joined
Apr 10, 2005
Messages
2,894
We need to get Samba file sharing working:
Bash:
yum install samba samba-client samba-common

A trimmed down working Config file:
Code:
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = myserver
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ==============================
[docker]
    guest ok = yes
    writable = yes
    browsable = yes
    path = /home/shared/docker

[shared]
    guest ok = yes
    writable = yes
    browsable = yes
    path = /home/shared

[hass]
    guest ok = yes
    writable = yes
    browsable = yes
    path = /home/shared/docker/homeassistant
 

patrick123

Expert Member
Joined
Apr 10, 2005
Messages
2,894
Installing Portainer to control or containers via the web:
Bash:
docker run -d \
--name portainer \
-p 9000:9000 \
-e TZ=Africa/Johannesburg \
portainer/portainer


Let the system update itself via watchtower:
Bash:
docker run -d \
    --name watchtower \
    --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower
 

patrick123

Expert Member
Joined
Apr 10, 2005
Messages
2,894
Grafana:
Bash:
mkdir -p /home/shared/docker/grafana/data

docker run -d \
  -p 3010:3000 \
-e TZ=Africa/Johannesburg \
  --name=grafana \
  -v /home/shared/docker/grafana/data:/var/lib/grafana \
  grafana/grafana


Almond Server, if required:
Bash:
mkdir -p /home/shared/docker/almond/almond-server

docker run -d -p 3001:3000 \
--restart=always \
--name=almond \
-e TZ=Africa/Johannesburg \
-v /home/shared/docker/almond/almond-server:/var/lib/almond-server \
stanfordoval/almond-server:latest-portable


Monitoring your containers within HA:
https://philhawthorne.com/ha-docker...t-to-monitor-start-or-stop-docker-containers/
Bash:
mkdir -p /home/shared/docker/dockermon

docker run -d \
--name=ha-dockermon --restart=always \
-e TZ=Africa/Johannesburg \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/shared/docker/dockermon:/config \
-p 8126:8126 philhawthorne/ha-dockermon
 

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
29,733
Why are you using docker run instead of docker compose? Pretty easy to convert: https://composerize.com/
e.g. PHPMyAdmin:
Code:
version: '3.3'
services:
    \:
        container_name: phpmyadmin
        environment:
            - MYSQL_ROOT_PASSWORD=MyPassword
            - PMA_HOST=mysql
            - PMA_PORT=3306
        ports:
            - '8080:80'
        image: \
and you could put them all in the same file and just run docker-compose up. So create all the directories, or just have it in the docker-compose file as well, just have the user put the docker-compose.yml in the right place (if that's even needed).
Plus add an env file rather so user changes passwords there.
 

patrick123

Expert Member
Joined
Apr 10, 2005
Messages
2,894
Why are you using docker run instead of docker compose? Pretty easy to convert: https://composerize.com/
e.g. PHPMyAdmin:
Code:
version: '3.3'
services:
    \:
        container_name: phpmyadmin
        environment:
            - MYSQL_ROOT_PASSWORD=MyPassword
            - PMA_HOST=mysql
            - PMA_PORT=3306
        ports:
            - '8080:80'
        image: \
and you could put them all in the same file and just run docker-compose up. So create all the directories, or just have it in the docker-compose file as well, just have the user put the docker-compose.yml in the right place (if that's even needed).
Thanks for this.
Before I started, I had never used docker or docker compose. These snippets came after many hours of me installing, testing, deleting, and reinstalling until I had a happy working collection.

As what I mature in using docker-compose, I will move them all into a compose file, and now that you have given me the links, I will definitely go explore. :thumbsup:
 

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
29,733
Thanks for this.
Before I started, I had never used docker or docker compose. These snippets came after many hours of me installing, testing, deleting, and reinstalling until I had a happy working collection.

As what I mature in using docker-compose, I will move them all into a compose file, and now that you have given me the links, I will definitely go explore. :thumbsup:
Good luck, I find it a lot easier than memorizing/copy-pasting commands. ;)
Just be careful of spacing, docker-compose is very finicky about that.

I suggest you use VS Code with the docker extension, has intellisense as well.
 

patrick123

Expert Member
Joined
Apr 10, 2005
Messages
2,894
Good luck, I find it a lot easier than memorizing/copy-pasting commands. ;)
Just be careful of spacing, docker-compose is very finicky about that.

I suggest you use VS Code with the docker extension, has intellisense as well.
Thanks, I will definitely delve into it. I actually have a txt file with these commands, typed up with their references and comments.
 

Johnatan56

Honorary Master
Joined
Aug 23, 2013
Messages
29,733
You get things like this:
754088
Tell you that it cannot work (red underline at end of brackets).
And then hover tips that usually also give default:
754090
And things like analogous statements.
754092
And then the default VS Code adherence to if the file is tab = 2 spaces, it will do that for you.
 

ebendl

Expert Member
Joined
Sep 27, 2004
Messages
4,427
Finally moved my Home Assistant over to an external SSD instead of the SD card this weekend. Did this because I seriously thought I corrupted my 4th SD card when my backup batteries powering the Pi died midway through loadshedding.

Followed this guide: https://community.home-assistant.io/t/hassio-booting-off-ssd-on-a-raspberry-pi-3b/124007

I'm currently running Raspbian lite, directly booting off the SSD (no SD card) and then running Hassio in Docker. It seems to boot fine, but rebooting unfortunately doesn't pick up the SSD -- I have to completely power down.

The basics was quite easy to set up, but the only major problem was restoring my Home Assistant from the SD card. I initially tried a Hass.io Snapshot (which was reported successful). Then I set up Home Assistant on Docker on the Pi, and when all was working, proceeded to restore the snapshot. Unfortunately it ended up restoring only part of my config -- most of the Yaml files were missing!

Luckily the SD card was still working and I could recover it using a Windows machine.

I can definitely report that on the Pi 3b+ everything is much faster using the SSD -- history and graphs load quickly. We'll see about the reliability!

Monitoring your containers within HA:
https://philhawthorne.com/ha-docker...t-to-monitor-start-or-stop-docker-containers/
Bash:
mkdir -p /home/shared/docker/dockermon

docker run -d \
--name=ha-dockermon --restart=always \
-e TZ=Africa/Johannesburg \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/shared/docker/dockermon:/config \
-p 8126:8126 philhawthorne/ha-dockermon

This is very cool, set it up to monitor my RTSP-Camera-person-detection Docker image which is running on a separate laptop. Planning on setting up Grafana and InfluxDB there too.
 
Top