Raspberry Pi & How to Self-Host anything
So you already have your RPi and the OS Setup
Self-Hosting can be simplified with Docker.
Thanks to the great work of the community that bundles a lot of Apps/services into docker container images and make them available, together with their code.
Install Docker
To install docker in the RPI, we need a different installation since their processors are ARM based.
1
apt-get update && sudo apt-get upgrade && curl -fsSL https://get.docker.com -o get-docker.sh
1
2
3
4
sh get-docker.sh && docker version
#Test that docker works with this image:
#sudo docker run hello-world
Install Docker-Compose
1
apt install docker-compose -y
Check the version with:
1
docker-compose --version
And check the status with:
1
2
3
4
systemctl status docker
#sudo systemctl start docker #if it is not running
#systemctl list-units --type=service
#systemctl list-units --type=service --state=running
Installing Portainer
1
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
Trying any App with Docker
Remember that the RPi works with an ARM processors, so expect some changes in the .yml configuration files when another compatible image has to be used.
When pulling the images, docker will find the one that suits your machine (if no specific version is specified) when available.
Make sure that the Docker image tag that you are pulling supports multi-architecture and that ARM (32 or 64) is between them.
Example: deploying several Apps at once with Docker-Compose
One App - Whoogle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
---
version: "2"
services:
whoogle:
image: benbusby/whoogle-search:latest
container_name: whoogle
ports:
- 5000:5000
restart: unless-stopped
#sudo docker run --name whoogle -d -p 5000:5000/udp -p 5000:5000/tcp \
#--restart=always benbusby/whoogle-search:latest
#docker run --publish 5000:5000 --detach --name whoogle benbusby/whoogle-search:latest
Several Apps - Raspberry Pi Media server: Docker Stack with NextCloud, Photoview, Navidrome
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
version: "3"
services:
db:
image: linuxserver/mariadb
restart: always
environment:
- MYSQL_DATABASE=photoview
- MYSQL_USER=photoview
- MYSQL_PASSWORD=photosecret
- MYSQL_RANDOM_ROOT_PASSWORD=1
volumes:
- db_data:/var/lib/mysql
photoview:
image: viktorstrate/photoview:2
restart: always
ports:
- "8099:80"
depends_on:
- db
environment:
- PHOTOVIEW_DATABASE_DRIVER=mysql
- PHOTOVIEW_MYSQL_URL=photoview:photosecret@tcp(db)/photoview
- PHOTOVIEW_LISTEN_IP=photoview
- PHOTOVIEW_LISTEN_PORT=80
- PHOTOVIEW_MEDIA_CACHE=/app/cache
volumes:
- api_cache:/app/cache
# Change This: to the directory where your photos are located on your server.
# If the photos are located at `/home/user/photos`, then change this value
# to the following: `/home/user/photos:/photos:ro`.
# You can mount multiple paths, if your photos are spread across multiple directories.
- ~/Docker/Syncthing/config/Photoview:/photos:ro #it respects your file system photo organization & remember to mention /photos/whatever_path in the initial setup
# volumes:
# db_data:
# api_cache:
syncthing:
image: ghcr.io/linuxserver/syncthing
container_name: syncthing
hostname: syncthing #optional
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Warsaw
volumes:
- /home/rpi_user_name/Docker/Syncthing/config:/config
- /home/rpi_user_name/Docker/Syncthing/Photoview:/data1
- /media/pi/Nowy/Syncthing_RPi:/data2
ports:
- 8384:8384
- 22000:22000/tcp
- 22000:22000/udp
- 21027:21027/udp
restart: unless-stopped
navidrome:
image: deluan/navidrome:latest
ports:
- "4533:4533"
environment:
# Optional: put your config options customization here. Examples:
ND_SCANSCHEDULE: 1h
ND_LOGLEVEL: info
ND_BASEURL: ""
volumes:
- "~/Docker/navidrome/data:/data"
- "~/Docker/Syncthing/config/Aficiones/Musica:/music:ro"
db:
image: linuxserver/mariadb
restart: always
container_name: nextclouddb
volumes:
- /home/rpi_user_name/Docker/nextcloud/db:/var/lib/mysql
environment:
- MYSQL_INITDB_SKIP_TZINFO=1
- MYSQL_ROOT_PASSWORD=rootpass
- MYSQL_PASSWORD=ncpass
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
app:
image: nextcloud
container_name: nextcloud
restart: always
ports:
- 8080:80
links:
- db
volumes:
- /home/rpi_user_name/Docker/nextcloud/html:/var/www/html
environment:
- MYSQL_PASSWORD=ncpass
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- NEXTCLOUD_TRUSTED_DOMAINS=http://192.168.3.31:8080 http://0.0.0.0:8080
duplicati:
image: ghcr.io/linuxserver/duplicati
container_name: duplicati
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Madrid
- CLI_ARGS= #optional
volumes:
- ~/Docker/Duplicati/config:/config
- ~/Docker:/source
- ~/Docker/backups:/backups
ports:
- 8200:8200
restart: unless-stopped
volumes:
db_data:
api_cache:
nextcloud:
db:
FAQ
Looking Forward to Self-Host other Apps?
- I have been consolidating a list of docker-compose files to deploy several F/OSS Apps in my Docker repository
- Also, I have created detailed guides of some of them in my Tech blog: https://fossengineer.com/tags/self-hosting/
Monitoring the server performance?
You can have a look on how the things are going with Netdata and Docker.