是用来学习docker而制作,都是一些很笨的办法,大神勿喷,谢谢
来自https://github.com/cppla/ServerStatus
server端
已经发布可以使用
docker pull hqhyco/serverstatus
下面记录下文件的内容都有什么
caddy是官网下来的,
ServerStatus是git下来
sergate是编译的
#Dockerfile
FROM ubuntu
MAINTAINER [email protected]
COPY caddy /caddy
COPY ServerStatus/server/sergate /sergate
COPY ServerStatus/web /web
COPY s.sh /s.sh
RUN chmod +x /s.sh
EXPOSE 80
EXPOSE 35601
ENTRYPOINT ["/s.sh"]
#Caddyfile
:80 {
root * /web
encode gzip
file_server
}
#s.sh脚本
#!/bin/bash
chmod +x /caddy/caddy
chmod +x /sergate
cd /caddy
./caddy start
cd /
./sergate --config=/config.json --web-dir=/web
#Dockerfile
FROM alpine
MAINTAINER [email protected]
COPY caddy /caddy
COPY ServerStatus/server/sergate /sergate
COPY ServerStatus/web /web
COPY s.sh /s.sh
RUN chmod +x /s.sh
EXPOSE 80
EXPOSE 35601
ENTRYPOINT ["sh" ,"/s.sh"]
#Caddyfile
:80 {
root * /web
encode gzip
file_server
}
#s.sh脚本
#!/bin/sh
chmod +x /caddy/caddy
chmod +x /sergate
/caddy/caddy start
/sergate --config=/config.json --web-dir=/web
#配置文件先写好
#80是网站的端口
#35601是连接客户端的端口
docker run -d --restart=always --name serverstatus -p 80:80 -p 35601:35601 -v /root/serverstatus/config.json:/ServerStatus/server/config.json hqhyco/serverstatus
配置文件范例
{"servers":
[
{
"username": "user1",
"password": "123456",
"name": "vps1",
"type": "KVM",
"host": "",
"location": "United States",
"disabled": false,
"region": "US"
},
{
"username": "user2",
"password": "123456",
"name": "vps2",
"type": "KVM",
"host": "",
"location": "United States",
"disabled": false,
"region": "US"
}
]
}
client客户端
已经发布可以使用
docker push hqhyco/clientstatus
下面记录下文件的内容都有什么
#Dockerfile
FROM ubuntu
MAINTAINER [email protected]
COPY ServerStatus/clients/client-linux.py /client-linux.py
COPY start.sh /start.sh
RUN apt update -y \
&& apt install python -y \
&& rm -rf /var/lib/apt/lists/* \
&& chmod +x /start.sh
ENTRYPOINT ["/start.sh"]
start.sh
#!/bin/bash
python client-linux.py SERVER=$1 USER=$2 PASSWORD=$3
build以后按下面代码使用
docker run -d --restart=always --name cs --net host hqhyco/clientstatus 127.0.0.1 username password
#或者先下载
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py'
#然后
docker run -d --name cs --net host -v "$PWD":/py python:slim python /py/client-linux.py SERVER=127.0.0.1 USER=user PASSWORD=password
127.0.0.1是服务端的ip
username是连接服务端的用户名
password是连接服务端的密码
这4个参数相当于给ENTRYPOINT [“/start.sh”]传3个参数,对应$1 $2 $3
实际容器最后会执行
/start.sh 127.0.0.1 username password
根据下面的文章理解
Dockerfile文件中的CMD和ENTRYPOINT指令差异对比
当然不想在docker里运行的话,可以在vps上直接,但是要先安装python
wget --no-check-certificate -qO client-linux.py 'https://raw.githubusercontent.com/cppla/ServerStatus/master/clients/client-linux.py' && nohup python client-linux.py SERVER=127.0.0.1 USER=user1 PASSWORD=123456 >/dev/null 2>&1 &