编辑
2025-05-17
部署项目遇到的问题
00

目录

项目部署教程
docker部署方式
修改后端项目docker-compose配置
重新安装项目

最近需要一个文档应用,需要支持设置文档过期时间与文档打开次数,即阅后自焚,于是上github找到一个特别匹配的项目。pastme:https://github.com/LucienShui/PasteMe

项目部署教程

docker部署方式

通过查看项目部署方式,查找到该项目可通过docker镜像形式部署,只需要使用该docker配置文件,输入命令,即可一件部署:

js
version: "3" services: pasteme-frontend: image: pasteme/frontend:3.4.1 container_name: pasteme-frontend depends_on: - pasteme-backend healthcheck: test: ["CMD", "curl", "-so", "/dev/null", "localhost:8080/usr/config.json"] interval: 45s timeout: 3s retries: 3 restart: always //前端页面端口可配置成其它端口,6001:8080 ports: - 80:8080 volumes: - ./data/nginx-logs/:/var/lib/pasteme/ - ./data/frontend-usr/:/www/pasteme/usr/ pasteme-backend: image: pasteme/go-backend:3.5.1 container_name: pasteme-backend depends_on: - pasteme-mysql healthcheck: test: ["CMD", "wget", "-O", "/dev/null", "localhost:8000/api/v3/?method=beat"] interval: 45s timeout: 3s retries: 3 restart: always volumes: - ./data/backend-config/:/etc/pastemed/ logging: driver: "json-file" options: max-file: "3" max-size: "128m" pasteme-mysql: image: mysql:5.5 container_name: pasteme-mysql healthcheck: test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] interval: 45s timeout: 3s retries: 3 restart: always command: [ '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ] environment: MYSQL_USER: username MYSQL_PASSWORD: password MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: pasteme MYSQL_MAX_ALLOWED_PACKET: 128M MYSQL_INNODB_LOG_FILE_SIZE: 64M volumes: - ./data/mysql:/var/lib/mysql logging: driver: "json-file" options: max-file: "3" max-size: "128m"

配置提示

其中前端项目可更换其它对外端口,即将ports: - 80:8080 修改为 ports: - 6001:8080。这样对外端口就为6001

在当前目录下执行命令即可下载安装镜像文件。

shell
docker-compose up -d

在安装过程中由于docker镜像网站被国内封禁。可添加国内镜像。添加源后再安装镜像即可。

shell
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": [ "https://docker.m.daocloud.io", "https://docker.imgdb.de", "https://docker-0.unsee.tech", "https://docker.hlmirror.com", "https://docker.1ms.run", "https://func.ink", "https://lispy.org", "https://docker.xiaogenban1993.com" ] } EOF #重启docker服务 sudo systemctl daemon-reload && sudo systemctl restart docker #验证源是否加载成功 sudo docker pull hello-world

项目部署后,发现文档有限制,只可创建最多查看3次的文档,需要修改后端代码,于是需要将docker内的开源后端项目改为本地编译的镜像。

修改后端项目docker-compose配置

将后端代码库通过git拉取到服务器内,后端开源项目地址https://github.com/PasteUs/PasteMeGoBackend 再将Dockerfile文件内的配置修改,添加go模块载入代理

config
go env -w GOPROXY=https://goproxy.cn

修改后配置文件

js
FROM pasteme/golang:1.16-alpine AS builder COPY ./ /go/src/github.com/PasteUs/PasteMeGoBackend WORKDIR /go/src/github.com/PasteUs/PasteMeGoBackend go env -w GOPROXY=https://goproxy.cn RUN go mod download RUN go build main.go RUN mkdir /pastemed && \ cp config.example.json docker-entrypoint.sh /pastemed/ && \ cp main /pastemed/pastemed FROM alpine:3 LABEL maintainer="Lucien Shui" \ email="lucien@lucien.ink" ENV TZ=Asia/Shanghai COPY --from=builder /pastemed /usr/local/pastemed RUN chmod +x /usr/local/pastemed/pastemed && \ mkdir /data && \ mkdir -p /etc/pastemed/ && \ apk --no-cache add build-base tzdata && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone CMD ["/usr/bin/env", "sh", "/usr/local/pastemed/docker-entrypoint.sh"] EXPOSE 8000

再修改原始的docker-compose文件配置 将加载的镜像修改为本地编译

config
修改前 image: pasteme/go-backend:3.5.1 修改后 build: ./pasteme-backend #该目录为拉取的代码目录

修改后的配置文件

shell
version: "3" services: pasteme-frontend: image: pasteme/frontend:3.4.1 container_name: pasteme-frontend depends_on: - pasteme-backend healthcheck: test: ["CMD", "curl", "-so", "/dev/null", "localhost:8080/usr/config.json"] interval: 45s timeout: 3s retries: 3 restart: always //前端页面端口可配置成其它端口,6001:8080 ports: - 80:8080 volumes: - ./data/nginx-logs/:/var/lib/pasteme/ - ./data/frontend-usr/:/www/pasteme/usr/ pasteme-backend: build: ./pasteme-backend container_name: pasteme-backend depends_on: - pasteme-mysql healthcheck: test: ["CMD", "wget", "-O", "/dev/null", "localhost:8000/api/v3/?method=beat"] interval: 45s timeout: 3s retries: 3 restart: always volumes: - ./data/backend-config/:/etc/pastemed/ logging: driver: "json-file" options: max-file: "3" max-size: "128m" pasteme-mysql: image: mysql:5.5 container_name: pasteme-mysql healthcheck: test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] interval: 45s timeout: 3s retries: 3 restart: always command: [ '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ] environment: MYSQL_USER: username MYSQL_PASSWORD: password MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: pasteme MYSQL_MAX_ALLOWED_PACKET: 128M MYSQL_INNODB_LOG_FILE_SIZE: 64M volumes: - ./data/mysql:/var/lib/mysql logging: driver: "json-file" options: max-file: "3" max-size: "128m"

重新安装项目

先删除原有的镜像再重新安装

shell
#查找原有镜像 docker images -a #删除镜像 docker rmi -f 6d46013a1ed 915d0aad7a5 d404d78aa79

根据修改配置文件安装镜像

shell
docker-compose up -d

安装成功后即可看到部署修改后的后端服务

本文作者:lsq_137

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!