joplin 是一款开源笔记应用,全平台适用,支持多种云端同步方式。最近体验了下感觉不错,尤其是可以自行搭建 server 服务端保存数据,适合喜欢管理整个数据流程的人士。下面介绍如何在服务器通过 docker 搭建 joplin server 的方法。

joplin 官网:https://joplinapp.org/
GitHub 主页:https://github.com/laurent22/joplin
各个平台客户端下载:https://joplinapp.org/download/

我的服务器系统平台是 Ubuntu 20.04。

docker 环境安装

首先如果安装过老版的 docker 先卸载:

sudo apt-get remove docker docker-engine docker.io containerd runc

安装基础环境:

 sudo apt-get update
 sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

添加 docker 官方 GPG key:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装 docker 和 docker-compose:

 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

docker 配置为非 root 用户,解决执行命令需要 sudo:

sudo groupadd docker
sudo usermod -aG docker $USER
su - ${USER}

配置 docker-compose

通过 docker-compose 可以方便的配置 docker 容器设置及多容器之间数据交互。

新建 joplin 文件夹用来存放配置 docker-compose.yml 以及 .env 环境变量文件,我喜欢放在 opt 路径下:

mkdir /opt/docker/joplin
cd /opt/docker/joplin

新建环境变量文件 .env 内容如下:

APP_BASE_URL=https://joplin.your.site
APP_PORT=22300
# 
DB_CLIENT=postgres
POSTGRES_PASSWORD=PASSWORD
POSTGRES_DATABASE=joplin
POSTGRES_USER=USERNAME
POSTGRES_PORT=5432
POSTGRES_HOST=localhost

上面的配置中需要自行修改几项:

  • APP_BASE_URL 修改为你实际访问 joplin 服务的外网地址,需要提前配置好 dns 映射,我是通过 cloudflare 管理的
  • POSTGRES_PASSWORD 修改数据库密码
  • POSTGRES_USER 修改数据库用户名

新建 docker-compose.yml 内容如下:

version: '3'
services:
    db:
        image: postgres:13
        volumes:
            - ./data/postgres:/var/lib/postgresql/data
        ports:
            - "5432:5432"
        restart: unless-stopped
        environment:
            - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
            - POSTGRES_USER=${POSTGRES_USER}
            - POSTGRES_DB=${POSTGRES_DATABASE}
        network_mode: host
    app:
        image: joplin/server:latest
        depends_on:
            - db
        ports:
            - "22300:22300"
        restart: unless-stopped
        environment:
            - APP_PORT=${APP_PORT}
            - APP_BASE_URL=${APP_BASE_URL}
            - DB_CLIENT=${DB_CLIENT}
            - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
            - POSTGRES_DATABASE=${POSTGRES_DATABASE}
            - POSTGRES_USER=${POSTGRES_USER}
            - POSTGRES_PORT=${POSTGRES_PORT}
            - POSTGRES_HOST=${POSTGRES_HOST}
        network_mode: host

docker-compose 会自动调用同一路径下的 .env 文件中定义的环境变量。

完成配置后启动容器:

docker-compose up -d

nginx 配置

外网访问上面定义的 url 后,需要通过反向代理将数据流传给 joplin server 端口 22300,我使用的是 nginx 配置如下:

server {
    listen        443 ssl http2;
    listen        [::]:443 ssl http2;
    server_name   joplin.your.site;
    include       my-server/ssl; 加入 ssl 相关配置

    location / {
        proxy_pass          http://127.0.0.1:22300;
        proxy_redirect      off;

        proxy_set_header    Host              $host;
        proxy_set_header    X-Real-IP         $remote_addr;
        proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto $scheme;
        proxy_set_header    Upgrade           $http_upgrade;
        proxy_set_header    Connection        "upgrade";
        proxy_http_version  1.1;
    }
}

完成后重启 nginx:

systemctl restart nginx

访问

配置好 docker 和 nginx 后就可以访问上面设置的 url 访问 joplin 了,默认会自动创建一个用户 admin@localhost,密码是 admin

第一次登录进去后最好修改下默认管理员密码,还可以创建多个账户。

如果要适用账户的邮件服务,需要额外配置 SMTP 相关的内容,这里不做介绍,新建账户的激活邮件可以在管理菜单中找到,没有配置邮件服务的话无法发送成功,可以手动将邮件中的账户激活链接发送给别人。

如果登录网址无法访问网页,可能是 docker 配置有问题,可以通过 log 查看是否有报错信息:

docker container list # 查询到容器的 ID
docker logs ID # 通过 joplin 的容器 ID 查询其日志

插件

joplin 桌面版支持安装插件,第三方插件有很多,可以在下面链接查找:Joplin Plugin Repository

参考链接

nstall Docker Engine on Ubuntu
How To Install and Use Docker on Ubuntu 20.04
docker logs
joplin server install
docker-compose.server.yml
.env-sample

标签:无

3 条评论

  1. php guider php guider

    Joplin is an impressive open-source note-taking application that's available on all major platforms. What really stands out is its flexibility to support multiple cloud synchronization methods and even the ability to host your own server, offering complete control over your data. I recently set up a Joplin Server on my Ubuntu 20.04 system using Docker, and the process was surprisingly smooth. The ability to configure Docker Compose and manage environment variables like APP_BASE_URL and POSTGRES_PASSWORD made the deployment both organized and efficient.

    For those new to Docker, the first step is to ensure a proper Install Docker on Ubuntu guide. It's a lifesaver for setting up the required Docker environment on your system. Configuring NGINX as a reverse proxy for SSL and secure access further enhanced the deployment experience.

    The default admin account provided (admin@localhost with the password admin) is a thoughtful addition for a quick setup, though it's advisable to change the password immediately for security. If you're looking for a self-hosted solution that combines productivity and privacy, Joplin paired with Docker is a fantastic choice. I highly recommend exploring the official documentation and GitHub repository for further customization options.

  2. php guider php guider

    Joplin is an impressive open-source note-taking application that's available on all major platforms. What really stands out is its flexibility to support multiple cloud synchronization methods and even the ability to host your own server, offering complete control over your data. I recently set up a Joplin Server on my Ubuntu 20.04 system using Docker, and the process was surprisingly smooth. The ability to configure Docker Compose and manage environment variables like APP_BASE_URL and POSTGRES_PASSWORD made the deployment both organized and efficient.

    For those new to Docker, the first step is to ensure a proper Install Docker on Ubuntu guide. It's a lifesaver for setting up the required Docker environment on your system. Configuring NGINX as a reverse proxy for SSL and secure access further enhanced the deployment experience.

    The default admin account provided (admin@localhost with the password admin) is a thoughtful addition for a quick setup, though it's advisable to change the password immediately for security. If you're looking for a self-hosted solution that combines productivity and privacy, Joplin paired with Docker is a fantastic choice. I highly recommend exploring the official documentation and GitHub repository for further customization options.

  3. Joplin is an impressive open-source note-taking application that's available on all major platforms. What really stands out is its flexibility to support multiple cloud synchronization methods and even the ability to host your own server, offering complete control over your data. I recently set up a Joplin Server on my Ubuntu 20.04 system using Docker, and the process was surprisingly smooth. The ability to configure Docker Compose and manage environment variables like APP_BASE_URL and POSTGRES_PASSWORD made the deployment both organized and efficient.

    For those new to Docker, the first step is to ensure a proper Install Docker on Ubuntu guide. It's a lifesaver for setting up the required Docker environment on your system. Configuring NGINX as a reverse proxy for SSL and secure access further enhance the deployment experience .

    The default admin account provided (admin@localhost with the password admin) is a thoughtful addition for a quick setup, though it's advisable to change the password immediately for security. If you're looking for a self-hosted solution that combines productivity and privacy , Joplin paired with Docker is a fantastic choice. I highly recommend exploring the official documentation and GitHub repository for further customization options.

你的评论