diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..29c4b2d Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index 277feca..8a668a6 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,42 @@ systemd 脚本放入: * 停止: `systemctl stop anylink` * 开机自启: `systemctl enable anylink` +## Docker + +1. 构建镜像 + + ```bash + #获取仓库源码 + git clone -b dev https://github.com/bjdgyc/anylink.git + # 构建镜像 + cd docker + docker build -t anylink . + ``` + +2. 生成密码 + + ```bash + docker run -it --privileged -e mode=password -e password=< your password > --rm anylink + ``` + +3. 生成jwt token + + ```bash + docker run -it --privileged -e mode=jwt --rm anylink + ``` + +4. 启动容器 + + ```bash + docker run -it --privileged \ + -e mode=pro \ + -e iproute=192.168.10.0/255.255.255.0 \ + -v :/anylink/conf \ + -v :/anylink/log \ + --restart=always + anylink + ``` + ## Setting diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..b240e3c --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:18.04 +WORKDIR / +COPY docker_entrypoint.sh docker_entrypoint.sh +RUN mkdir /anylink && apt update && apt install -y wget iptables tar iproute2 +ENTRYPOINT ["/docker_entrypoint.sh"] +#CMD ["/anylink/anylink","-conf=/anylink/conf/server.toml"] diff --git a/docker/docker_entrypoint.sh b/docker/docker_entrypoint.sh new file mode 100755 index 0000000..fff9331 --- /dev/null +++ b/docker/docker_entrypoint.sh @@ -0,0 +1,37 @@ +#! /bin/bash +version=(`wget -qO- -t1 -T2 "https://api.github.com/repos/bjdgyc/anylink/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g'`) +count=(`ls anylink | wc -w `) +wget https://github.com/bjdgyc/anylink/releases/download/${version}/anylink-deploy.tar.gz +tar xf anylink-deploy.tar.gz +rm -rf anylink-deploy.tar.gz +if [ ${count} -eq 0 ]; then + echo "init anylink" + mv anylink-deploy/* anylink/ +else + if [ ! -d "/anylink/log" ]; then + mv anylink-deploy/log anylink/ + fi + if [ ! -d "/anylink/conf" ]; then + mv anylink-deploy/conf anylink/ + fi + echo "update anylink" + rm -rf anylink/ui anylink/anylink anylink/files + mv anylink-deploy/ui anylink/ + mv anylink-deploy/anylink anylink/ + mv anylink-deploy/files anylink/ +fi +rm -rf anylink-deploy +sysctl -w net.ipv4.ip_forward=1 +if [[ ${mode} == pro ]];then + iptables -t nat -A POSTROUTING -s ${iproute} -o eth0 -j MASQUERADE + iptables -L -n -t nat + /anylink/anylink -conf=/anylink/conf/server.toml +elif [[ ${mode} == password ]];then + if [ -z ${password} ];then + echo "invalid password" + else + /anylink/anylink -passwd ${password} + fi +elif [[ ${mode} -eq jwt ]];then + /anylink/anylink -secret +fi