diff --git a/docker/Dockerfile b/docker/Dockerfile index 4fc28e1bb..4a8d5b664 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -86,11 +86,4 @@ RUN cd /root && wget https://gitee.com/Lyon1998/pikapython/attach_files/1420660/ mv frp_0.48.0_linux_amd64/frpc /usr/local/bin/frpc COPY frpc.ini /etc/frpc.ini -ARG FRPC_SERVER_ADDR -ARG FRPC_SERVER_PORT -ARG FRPC_REMOTE_PORT -ARG FRPC_TOKEN -RUN sed -i "s|%FRPC_SERVER_ADDR%|${FRPC_SERVER_ADDR}|" /etc/frpc.ini && \ - sed -i "s|%FRPC_SERVER_PORT%|${FRPC_SERVER_PORT}|" /etc/frpc.ini && \ - sed -i "s|%FRPC_REMOTE_PORT%|${FRPC_REMOTE_PORT}|" /etc/frpc.ini && \ - sed -i "s|%FRPC_TOKEN%|${FRPC_TOKEN}|" /etc/frpc.ini +COPY frpc.sh /etc/frpc.sh diff --git a/docker/frpc.ini b/docker/frpc.ini index 3e71b506c..78934ef81 100644 --- a/docker/frpc.ini +++ b/docker/frpc.ini @@ -1,12 +1,14 @@ -# 全局配置 +####### Frpc config ####### + [common] server_addr = %FRPC_SERVER_ADDR% server_port = %FRPC_SERVER_PORT% token = %FRPC_TOKEN% -# SSH代理配置 [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = %FRPC_REMOTE_PORT% + +####### Frpc config ####### diff --git a/docker/frpc.sh b/docker/frpc.sh new file mode 100644 index 000000000..bdd226c45 --- /dev/null +++ b/docker/frpc.sh @@ -0,0 +1,6 @@ +sed -i "s|%FRPC_SERVER_ADDR%|${FRPC_SERVER_ADDR}|" /etc/frpc.ini && \ +sed -i "s|%FRPC_SERVER_PORT%|${FRPC_SERVER_PORT}|" /etc/frpc.ini && \ +sed -i "s|%FRPC_REMOTE_PORT%|${FRPC_REMOTE_PORT}|" /etc/frpc.ini && \ +sed -i "s|%FRPC_TOKEN%|${FRPC_TOKEN}|" /etc/frpc.ini +cat /etc/frpc.ini +/usr/local/bin/frpc -c /etc/frpc.ini diff --git a/docker/run.sh b/docker/run.sh index 45edb757f..77021655c 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,13 +1,9 @@ #!/bin/bash -DOCKER_NAME=pikadev - -docker rm $DOCKER_NAME -f - # 解析命令行参数 while getopts ":p:s:t:r:" opt; do case $opt in - p) frpc_port=$OPTARG;; + p) frpc_server_port=$OPTARG;; s) frpc_server_addr=$OPTARG;; t) frpc_token=$OPTARG;; r) frpc_remote_port=$OPTARG;; @@ -15,27 +11,33 @@ while getopts ":p:s:t:r:" opt; do esac done -# 检查是否设置了frpc_port参数 -if [ -n "$frpc_port" ]; then +DOCKER_NAME="pikadev" +if [ -n "$frpc_remote_port" ]; then + DOCKER_NAME+="_$frpc_remote_port" +fi + +# 检查是否设置了frpc_server_port参数 +if [ -n "$frpc_server_port" ]; then # 启动frpc echo "Starting frpc..." - docker run -d --name $DOCKER_NAME \ + docker rm $DOCKER_NAME -f + docker run -it --name $DOCKER_NAME \ --restart always \ -w /root/pikascript \ -e FRPC_REMOTE_PORT=$frpc_remote_port \ -e FRPC_SERVER_ADDR=$frpc_server_addr \ -e FRPC_SERVER_PORT=$frpc_server_port \ -e FRPC_TOKEN=$frpc_token \ - $DOCKER_NAME \ - /usr/local/bin/frpc -c /etc/frpc.ini + pikadev \ + bash /etc/frpc.sh echo "frpc started." else # 不启动frpc - echo "frpc_port is not set. Skipping frpc startup." + echo "frpc_server_port is not set. Skipping frpc startup." + docker rm $DOCKER_NAME -f docker run -it --name $DOCKER_NAME \ --restart always \ -w /root/pikascript \ - $DOCKER_NAME \ + pikadev \ bash fi -