diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8325abf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,42 @@ +FROM node:alpine3.17 + +# 项目地址(国内加速) +ARG gitUrl="https://ghproxy.com/https://github.com/nn200433/snapdrop.git" + +# 定义环境变量 +ENV TZ=Asia/Shanghai +ENV PORT=3000 +ENV OPTIONS= + +# 安装一些常用组件 +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \ + apk add -U --no-cache \ + ca-certificates \ + bash \ + curl \ + git \ + openssh \ + tzdata && \ + cp /usr/share/zoneinfo/${TZ} /etc/localtime && \ + echo ${TZ} > /etc/timezone && \ + apk del tzdata && \ + mkdir -p /home + +# 下载项目 +RUN cd /home && \ + git clone --depth=1 "${gitUrl}" && \ + cd snapdrop && chmod +x entrypoint.sh + +# 编译项目 +RUN cd /home/snapdrop && \ + npm config set registry https://registry.npm.taobao.org && \ + # npm install -g pm2 && \ + npm install + +# 指定默认工作目录 +WORKDIR /home/snapdrop + +# 默认3000端口 +EXPOSE 3000/tcp + +ENTRYPOINT ["/home/snapdrop/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index da6c169..d77a724 100755 --- a/README.md +++ b/README.md @@ -15,3 +15,29 @@ Make sure to check your ip address using your OS command. By default, it is used inside the LAN.\ Users who are not in the same LAN can establish a connection by entering the same room name.\ Enter a blank room name to return to LAN mode. + +## How to use Docker + +docker: + +```bash +docker run -itd --name=snapdrop --net=host --restart=unless-stopped -e PORT=5000 -e OPTIONS=public nn200433/snapdrop:latest +``` + +docker-compose: + +```yml +version: '3' +services: + snapdrop: + image: nn200433/snapdrop:latest + container_name: snapdrop + restart: unless-stopped + network_mode: host + environment: + # 默认3000 + - PORT=5000 + - TZ=Asia/Shanghai + # 默认内网 + - OPTIONS=public +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..868680f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3' +services: + snapdrop: + image: nn200433/snapdrop:1.0 + container_name: snapdrop + restart: unless-stopped + network_mode: host + environment: + - TZ=Asia/Shanghai + - OPTIONS=public \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..755a992 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# 启动传送 +if [ -n "${OPTIONS}" ]; then + echo "即将启动传送..." + echo "参数:OPTIONS = ${OPTIONS}" + #exec pm2 start index.js -- ${OPTIONS} + exec node index.js -- ${OPTIONS} +else + echo "即将启动传送..." + #exec pm2 start index.js + node index.js +fi \ No newline at end of file