官方发布的宝塔镜像基于centos,国内版宝塔,个人喜欢国际版
运行环境
- X96MAX+_arm64(4+32G)
- 带Docker的OPenWrt系统
安装
手动安装
- docker安装debian
1 2 3 4
| # 拉取最小化 debian 镜像,作为基础环境 docker pull debian:unstable-slim # 以 host 模式启动镜像,自动映射所有端口,如果在 root 目录下执行,会将宝塔站点目录挂载到 root/wwwroot 目录下 docker run -itd --name baota --net=host --restart always -v ~/wwwroot:/www/wwwroot debian:unstable-slim bash
|
- 进入系统安装依赖
1 2 3 4
| # 进入 debian 系统 docker exec -it baota bash # 依赖安装 apt-get update && apt install -y wget procps
|
- 安装宝塔面板
1
| wget -O install.sh http://www.aapanel.com/script/install-ubuntu_6.0_en.sh && bash install.sh aapanel
|
- 设置开机自启
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| # 创建自启文件 echo '#!/bin/sh \n\ etc/init.d/bt start \n\ tail -f /dev/null' >> /bt.sh chmod +x /bt.sh # 退出容器 exit # 关闭原容器 docker stop baota # 将原容器打包成新镜像 docker commit bt new_baota # 删除原容器、原镜像 docker rm baota && docker rmi debian:unstable-slim # 从新镜像启动一个新容器 docker run -tid --name baota --net=host --restart always -v ~/wwwroot:/www/wwwroot --entrypoint=/bin/bash new_baota /bt.sh
|
Dockerfile安装
Dockerfile文件代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| FROM debian:unstable-slim
RUN apt-get update && apt-get install -y wget procps && \ wget -O install.sh http://www.aapanel.com/script/install-ubuntu_6.0_en.sh && echo y | bash install.sh aapanel && \ apt-get clean && \ echo '#!/bin/sh \n\ etc/init.d/bt start \n\ tail -f /dev/null' >> /bt.sh && \ chmod +x /bt.sh
EXPOSE 22 3306 443 80 888 7800
CMD /bt.sh
|
- 构建
- 运行
1
| docker run -itd --name baota --net=host --restart always -v ~/wwwroot:/www/wwwroot baota:latest
|
排障
- nginx 的80端口被 OPenWRT 占用导致 nginx 无法启动
解决方法:更改nginx运行端口
修改www/server/panel/vhost/nginx/
目录下0.default.conf
和phpfpm_status.conf
文件里的端口为81即可
备份与恢复
本地
1 2 3 4 5 6 7
| # 备份 docker commit baota baota:latest docker save baota:latest | gzip > baota:latest.tar.gz
# 恢复 gunzip -c baota:latest.tar.gz | docker load docker run -itd --name baota --net=host --restart always -v ~/wwwroot:/www/wwwroot --entrypoint=/bin/bash baota:latest /bt.sh
|
云端(Docker Hub)
1 2 3 4 5 6 7 8 9 10
| # 备份 docker login # 登录 Docker Hub docker commit baota baota:latest # 将容器打包成镜像 docker images # 查看镜像ID docker tag [镜像ID] [username]/baota:latest # 打上Tag,username替换为自己的 docker push [username]/baota:latest # 上传到 Docker Hub
# 恢复 docker pull [username]/baota:latest docker run -itd --name baota --net=host --restart always -v ~/wwwroot:/www/wwwroot --entrypoint=/bin/bash pbloods/baota:latest /bt.sh
|
我的备份
宝塔登录地址: https://IP:7800/admin
用户名: username
密码: password
debian + 国际版宝塔(占用1.3G)
1
| docker pull pbloods/baota
|
lnmp 宝塔(占用4.0G)
nginx-1.21.4
mysql-5.5.62
php-7.4
官方自启脚本,覆盖根目录下的bt.sh
即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH
init_path=/etc/init.d Root_Path=`cat /var/bt_setupPath.conf` Setup_Path=$Root_Path/server/mysql Data_Path=$Root_Path/server/data
soft_start(){ ${init_path}/nginx start ${init_path}/php-fpm-74 start ${init_path}/pure-ftpd start ${init_path}/bt restart pkill crond /sbin/crond /usr/sbin/sshd -D & }
is_empty_Data(){ return `ls -A ${Data_Path}/|wc -w` }
init_mysql(){ # initialize_mysql if [ -f /init_mysql.sh ];then sh /init_mysql.sh rm -f /init_mysql.sh fi }
start_mysql(){ chown -R mysql:mysql ${Data_Path} chgrp -R mysql ${Setup_Path}/. ${init_path}/mysqld start rm -f /init_mysql.sh }
soft_start > /dev/null is_empty_Data > /dev/null if [ $? == 0 ];then init_mysql > /dev/null else start_mysql > /dev/null fi tail -f /dev/null
|