Deploy Joplin with .env File and Docker
Deploy Joplin with .env File and Docker

Starting Point: https://docs.vultr.com/how-to-host-a-joplin-server-with-docker-on-ubuntu

***Make Ubuntu 24.04 Proxmox CT and install docker ***

Script wright up https://raspberrytips.com/docker-on-raspberry-pi/

curl -sSL https://get.docker.com | sh

Add new user

adduser [username]
adduser [username] sudo
addeser [username] docker

Login as new user

sudo passwd -l root

**Now start setting up Joplin **

sudo mkdir /opt/joplin

cd /opt/joplin/

sudo nano joplin-docker-compose.yml

**This Juplin setup will also use docker for nginx proxy **

version: '3'

services:
  db:
    image: postgres:13
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: always
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_DB=${POSTGRES_DB}

  app:
    image: joplin/server:latest
    container_name: joplin-server
    depends_on:
      - db
    ports:
      - "8080:8080"
    restart: always
    environment:
      - APP_PORT=8080
      - APP_BASE_URL=${APP_BASE_URL}
      - DB_CLIENT=pg
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DATABASE=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PORT=5432
      - POSTGRES_HOST=db

  nginx:
    image: nginx:latest
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - ./nginx/joplin-server.conf:/etc/nginx/conf.d/joplin-server.conf
      - ./nginx/log:/var/log/nginx
    depends_on:
      - app
    restart: always
version: '3'

services:
  db:
    image: postgres:13
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    restart: always
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_DB=${POSTGRES_DB}

  app:
    image: joplin/server:latest
    container_name: joplin-server
    depends_on:
      - db
    ports:
      - "8080:8080"
    restart: always
    environment:
      - APP_PORT=8080
      - APP_BASE_URL=${APP_BASE_URL}
      - DB_CLIENT=pg
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DATABASE=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PORT=5432
      - POSTGRES_HOST=db

  nginx:
    image: nginx:latest
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - ./nginx/joplin-server.conf:/etc/nginx/conf.d/joplin-server.conf
      - ./nginx/log:/var/log/nginx
    depends_on:
      - app
    restart: always

Setup for nginx

sudo mkdir -p ./nginx/log
sudo mkdir -p ./nginx/conf.d

sudo nano ./nginx/joplin-server.conf

Dont Forget to change the # to the right number

server {
    listen 80;
    listen [::]:80;
    server_name 192.168.0.#;  # Replace with the IP address of your Docker host

    error_log /var/log/nginx/joplin-server.error;

    location / {
        proxy_pass http://192.168.0.#:8080;  # This remains the same (proxying to Joplin container)
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
server {
    listen 80;
    listen [::]:80;
    server_name 192.168.0.#;  # Replace with the IP address of your Docker host

    error_log /var/log/nginx/joplin-server.error;

    location / {
        proxy_pass http://192.168.0.#:8080;  # This remains the same (proxying to Joplin container)
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Build .env file to store info

sudo nano .env

POSTGRES_PASSWORD=Your-Password-here
POSTGRES_USER=joplin-user
POSTGRES_DB=joplindb
APP_BASE_URL=http://192.168.0.#:80
POSTGRES_PASSWORD=Your-Password-here
POSTGRES_USER=joplin-user
POSTGRES_DB=joplindb
APP_BASE_URL=http://192.168.0.#:80

Set Permissions on the .env File

sudo chmod 600 .env
sudo chown ve:ve .env # Or the specific user that needs access

Run the docker compose file start the job

sudo docker compose --env-file .env -f joplin-docker-compose.yml up -d

 

  1. Log in to the Joplin server with the following default email and password.

    • Email: admin@localhost
    • Password: admin