# Docker部署Minimalist-web-notepad

# 前言

近期工作需要一个能多端同步的记事本,在线笔记对我来说太大,又没什么隐私需求,所以在小众论坛寻找符合我需求的工具,找下来发现 Minimalist-web-notepad 这个小工具还蛮适合我的,Minimalist-web-notepad是一款类似于notepad的纯文本笔记本,可以用来做记事本,也可以用来做临时记录的工具,但依赖于PHP环境,我不太想在轻量服务器中再搞个 PHP 环境,于是想到 Docker 方案,网上冲浪找了一圈发现还真有对应的镜像,于是直接开搞。

# Docker 的基本安装与操作

# 1、安装

$ sudo apt install docker.io

# 2、基本操作

$ docker -v									# 检查 docker 版本
$ sudo docker ps							# 查看在运行的容器
$ sudo docker ps -a							# 查看所有容器(包括已经停止的)
$ sudo docker stop <CONTAINER ID ro NAMES>	# 停止一个在运行的容器
$ sudo docker start <CONTAINER>				# 重新运行一个已经停止的容器

$ systemctl status docker					# 检查 docker 状态

# Minimalist-web-notepad的安装与配置

# 1、下载镜像

$ sudo docker pull jdreinhardt/minimalist-web-notepad
Using default tag: latest
latest: Pulling from jdreinhardt/minimalist-web-notepad
bf5952930446: Pull complete
a409b57eb464: Pull complete
3192e6c84ad0: Pull complete
43553740162b: Pull complete
d8b8bba42dea: Pull complete
eb10907c0110: Pull complete
10568906f34e: Pull complete
03fe17709781: Pull complete
98171b7166c8: Pull complete
3978c2fb05b8: Pull complete
71bf21524fa8: Pull complete
24fe81782f1c: Pull complete
7a2dfd067aa5: Pull complete
4f55e0effe4d: Pull complete
e796f788f07f: Pull complete
7c215e9ce78c: Pull complete
Digest: sha256:efc19bf1e39f520fe4757606f78811b1f6e7a770b560e269631c384adf019910
Status: Downloaded newer image for jdreinhardt/minimalist-web-notepad:latest
docker.io/jdreinhardt/minimalist-web-notepad:latest

# 2、创建数据目录

$ sudo mkdir -p ~/data/webnotepad		# notepad 所有的笔记都会在这个文件夹中记录一份
$ sudo chmod -R 777 ~/data/webnotepad/ 	# 给足权限

# 3、创建 Minimalist 容器

$ sudo docker run -d --name notepad --restart always -p 7001:80 -v ~/data/webnotepad/data:/var/www/html/_tmp jdreinhardt/minimalist-web-notepad:latest

# docker run: 运行一个新的容器
# -d: 在后台(守护进程)模式下运行容器
# --name notepad: 为容器指定名称为"notepad"
# --restart always: 在容器退出时,总是自动重启容器
# -p 7001:80: 将主机的端口7001映射到容器的端口80
# -v ~/data/webnotepad/data:/var/www/html/_tmp: 将主机的~/data/webnotepad/data目录挂载到容器的/var/www/html/_tmp目录
# jdreinhardt/minimalist-web-notepad:latest: 使用镜像jdreinhardt/minimalist-web-notepad的最新版本作为容器的基础镜像

至此,通过 ip:port 即可访问 Minimalist Web Notepad

# Nginx 转发端口

$ sudo vim /etc/nginx/nginx.conf

# 1、HTTP 解析

...
server {
        listen 80;
        server_name notes.mallocx.com;
        location / {
                proxy_set_header Host $host;
                proxy_pass http://localhost:7001;
        }
}
...

# 2、HTTPS 解析

...
server {
        listen 443 ssl;
        server_name notes.mallocx.com;
        ssl_certificate /home/*****/****/notes/notes.mallocx.com_bundle.crt;
        ssl_certificate_key /home/*****/****/notes/notes.mallocx.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        location / {
                proxy_set_header Host $host;
                proxy_pass http://localhost:7001;
        }
}
....
$ nginx -s reload 	# 重启nginx