Hi,
after I managed to host my own Joplin server on a Raspberry Pi, I decided to write a guide that might help other people. If you spot any mistakes, please reply to me!
The guide was lastly updated on 02.03.2022.
1. Dynamic DNS
If you didn't get a static IP address from your ISP, you will need a Dynamic DNS service. This sets a hostname which will be redirected to your IP. I use No-IP because it is free and has always worked out for me. So create an account here and set a hostname with your (external) IP address, which you can read here. Make sure you don't have a VPN active, because then the IP address will be different.
2. Port forwarding
For all this fun to work, you need to give the RasPi a static IP in your router and set up port forwarding to it for port 80 and 443. There are enough instructions for this elsewhere.
3. Raspberry Pi OS 64bit
Raspberry Pi OS (formerly Raspbian) is 32bit by default. But for the server you need a 64bit system. Starting with the Raspi 3 (and some models of the 2nd generation) a 64bit chip is installed. To use the 64bit system you now need a SD card on which you write the beta version of Raspberry Pi OS in the 64bit variant: Link (thanks to @dpoulton for the hint!). For writing you can either use the Raspberry Pi Imager, or e.g. the Win32 Disk Imager. There are enough instructions elsewhere.
After the image has been written, remove the SD card and reinsert it once again into the PC. The boot partition should now appear in the file manager. Create an empty file there with the name "ssh" (thanks to @seatrout for the hint!) and make sure that it is created without a file extension. Then put the SD card in the Raspberry Pi, boot it up and connect via SSH. Keep in mind to change the default password: Link
4. Docker and docker-compose
Type in a terminal window, or via SSH the following commands (each line separately):
sudo apt update && sudo apt upgrade
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker ${USER}
Then reboot your Raspi:
sudo reboot now
Docker is installed, now follow Docker compose:
sudo apt-get install libffi-dev libssl-dev
sudo apt install python3-dev
sudo apt-get install -y python3 python3-pip
sudo pip3 install docker-compose
This will install docker-compose.
5. Apache web server
In a terminal window, or via SSH, type the following command:
sudo apt install apache2
Further configuration is not necessary until later.
6. Certbot:
To create Certbot and thus an SSL certificate, enter the following commands:
sudo apt install snapd
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --apache
After the last command you have to login with your email address and accept the terms. Then enter your previously given hostname from No-IP.
Afterwards check this by typing the hostname of No-IP into your browser. You should now be taken to the default Apache page via HTTPS. If you want, you can disable port forwarding for port 80 now.
7. Apache again
Now the further configuration. Enable the proxy modules:
sudo a2enmod proxy
sudo a2enmod proxy_http
And open the config for ssl:
sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf
Add here between the lines <VirtualHost *:443>
and </VirtualHost>
the following lines:
ProxyPreserveHost On
ProxyPass "/joplin" http://localhost:22300
ProxyPassReverse "/joplin" http://localhost:22300
And restart Apache:
sudo systemctl restart apache2
8. Joplin server
Now create a docker-compose.yml
file....
nano docker-compose.yml
...and replace DOMAIN.COM
with your hostname from No-IP. Big thanks to @etho201 and @florider at this point!
In the line image: etechonomy/joplin-server:latest
you can choose, which version of the server you will be running. Choose the best one for you (take a look at the changelogs and the forum) and then type the corresponding tag behind the colon (in this example it is the latest
- tag,). The tags can be viewed here: etechonomy/joplin-server - tags.
version: '3'
services:
db:
restart: unless-stopped
image: postgres:13.1
ports:
- "5432:5432"
volumes:
- /foo/bar/joplin-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=joplin
- POSTGRES_USER=joplin
- POSTGRES_DB=joplin
app:
environment:
- APP_BASE_URL=https://DOMAIN.COM/joplin
- APP_PORT=22300
- POSTGRES_PASSWORD=joplin
- POSTGRES_DATABASE=joplin
- POSTGRES_USER=joplin
- POSTGRES_PORT=5432
- POSTGRES_HOST=db
- DB_CLIENT=pg
restart: unless-stopped
image: etechonomy/joplin-server:latest
ports:
- "22300:22300"
depends_on:
- db
Now enter the following command to start Docker compose. This process will take a good while the first time you call it and after each update.:
docker-compose up
Check if you get to the Joplin server login page with your hostname from No-IP and a final /joplin
. If so, stop the server again with Ctrl + C
and start it in detached
mode to let it run in the background:
docker-compose up -d
9. Login
To login, browse to your hostname with a final /joplin
. The default Email is admin@localhost
with admin
as password. Please change those credentials immediately and add a non-admin user under the Users
tab for syncing with joplin. Keep in mind that the server is accessible to anyone on the Internet and therefore strong passwords are highly recommended.
10. Activate Dynamic-DNS
To keep the IP address at No-IP up to date, you still have to install and set up the update client of No-IP with this instruction. In order to make the service active even after a reboot, enter the following command:
sudo crontab -e
and add the following line to the end of the document:
@reboot sudo /usr/local/bin/noip2
11. Updates
Be sure to always have a backup of your data before changing anything!
If you want to update the server and have not selected a "variable" tag (master or latest), first stop the server:
docker-compose down
And edit the docker-compose.yml
file according to your needs (described at point 8):
nano docker-compose.yml
After the change, start the server with
docker-compose up
and check if everything runs fine. If so, stop the server again with Ctrl + C
and start it in detached
mode to let it run in the background:
docker-compose up -d
Kind regards
Mister Kanister