在各种机器上部署docker,包括:amd64笔记本ubuntu22.04、aarch64 华为 麦芒5 postmarketOS、armv7迅雷玩客云armbian。 在docker上部署各种容器,包括:监控面板、mysql、nginx、tomcat、wordpress、rabbitmq、zookeeper、kafka ----------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------- docker常用命令: 对容器修改后保存或者用于备份或者用于修改运行参数:docker commit 命令动态更新容器配置docker update 。需要详细研究,内容比较多且变化比较大。 对容器指定hostname:在run的时候加参数--hostname=xxx 进入容器终端:docker exec -it xxx bash 查看容器信息:docker inspect 停止容器:docker stop xxx 启动容器:docker start xxx 删除容器:docker rm xxx 删除容器镜像:docker rmi xxx ----------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------- ---------------------------------------amd64笔记本---ubuntu22.04上部署docker--------------------------------------------------- sudo apt install -y apt-transport-https ca-certificates curl software-properties-common curl -L https://mirrors-i.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors-i.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ jammy stable" sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io sudo docker run hello-world //配置国内镜像加速 sudo vi vi /etc/docker/daemon.json { "registry-mirrors": [ "https://docker.registry.cyou", "https://docker-cf.registry.cyou", "https://dockerpull.com", "https://dockerproxy.cn", "https://docker.1panel.live" ] } sudo systemctl daemon-reload sudo systemctl restart docker ----------------------------------------------------------------------------------------------------------------------------- -----------------------------------------aarch64 华为 麦芒5 postmarketOS alpine上部署docker------------------------------------ 给麦芒5手机刷postmarketos操作系统(alpinelinux),需要先解锁bootloader 先安装系统制作工具Pmbootstrap 详见网址:https://wiki.postmarketos.org/wiki/Pmbootstrap 在ubuntu22.04下(因为python版本需要至少3.10),本人麦芒5,codename是milan,查机器code页面:https://wiki.postmarketos.org/wiki/Devices +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sudo apt install python3-pip pip install tomli git clone --depth=1 https://gitlab.com/postmarketOS/pmbootstrap.git mkdir -p ~/.local/bin ln -s "$PWD/pmbootstrap/pmbootstrap.py" ~/.local/bin/pmbootstrap PATH="$HOME/.local/bin:$PATH" #验证版本信息 pmbootstrap --version +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 修改pmbootstrap镜像源: pmbootstrap config mirrors.alpine https://mirrors.aliyun.com/alpine/ pmbootstrap config mirrors.pmaports https://mirrors.aliyun.com/postmarketOS/ 或者 pmbootstrap config mirrors.alpine https://mirrors.tuna.tsinghua.edu.cn/alpine/ pmbootstrap config mirrors.pmaports https://mirrors.tuna.tsinghua.edu.cn/postmarketOS/ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pmbootstrap init (UI选phosh,语言选英文) pmbootstrap pull pmbootstrap install 进入手机自带的bootloader模式usb连接开刷 pmbootstrap flasher flash_lk2nd pmbootstrap flasher flash_rootfs 拔掉usb线重启手机按音量下键进入lk2nd的bootloader模式再连线usb开刷 pmbootstrap flasher flash_kernel over,重启手机,耐心等待会重启(很多很多很多次。。。)而且看起来像要起不来的样子^_^。 按linux操作系统安装docker。 sudo apk add docker sudo addgroup ${USER} docker sudo rc-update add docker default sudo rc-service docker start 其他:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 修改apk镜像源: /etc/apk/repositories中 http://mirrors.tuna.tsinghua.edu.cn/postmarketOS/master http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community pmbootstrap源恢复成原来的: Reset to default works as with all config options: pmbootstrap config -r mirrors.alpine pmbootstrap config -r mirrors.pmaports 相关网址: https://wiki.postmarketos.org/wiki/Pmbootstrap https://wiki.postmarketos.org/wiki/Devices -------------------------------------------------------------------------------------------------------------------------------- --------------------------------------armv7迅雷玩客云armbian上部署docker------------------------------------------------------ 1) 刷入方法:电脑连接玩客云靠近hdmi的USB口,短接刷机触点或者按住复位键的同时给玩客云通电,即可使用Aml Burn Tool软件直接烧录固件至玩客云。 有的板子不需要短接。。。 初始账号密码 root 1234 刷机包源下载地址:https://github.com/hzyitc/armbian-onecloud/releases 注意后缀带Burn的才是直刷包,其他都是USB启动包。 例如:Armbian_23.05.0-trunk_Onecloud_bullseye_edge_6.3.1.img.xz 2) 玩客云用网线连接路由器.插上电源. 开机后,进入上级路由器查看设备:onecloud 的ip地址 3) 保证windows电脑在同一路由器下,打开putty 输入onecloud的ip地址,打开 用户名:root,密码:1234 进入之后让你创建新用户,返回即可 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 更换源:nano /etc/apt/sources.list # 默认注释了源码镜像以提高 apt update 速度 # 清华大学的软件源 deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //安装docker sudo apt install docker.io +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ntfs盘挂载需要安装ntfs-3g blkid查看磁盘uuid --------------------------------------------------------------------------------------------------------------------------------- -------------------------------------docker上---监控面板安装----------------------------------------------------------------------- 可视化面板有很多,比如1panel面板、青龙面板、casaos等。 1panel面板,官网:https://1panel.cn/ sudo docker run -d \ --name=1panel \ -p 80:80 \ -p 8080:8080 \ -p 20:20 \ -p 21:21 \ -p 22:22 \ -p 8081:8081 \ -v /path/to/1panel/data:/1panel/data \ 1panel/1panel:latest ++++++++++++++++++++++++++++++++++++++ fastos面板 sudo docker run --restart always --name fast -p 8081:8081 -d -v /var/run/docker.sock:/var/run/docker.sock wangbinxingkong/fast 安装完成后在浏览器访问 http://服务器IP地址或域名:8081 ,默认用户名和密码是root/1234。 ++++++++++++++++++++++++++++++++++++++ casos面板,官网:https://www.casaos.io sudo docker run -d \ --name=casaos \ --privileged \ -v /path/to/casaos/data:/data \ -p 80:80 \ -p 443:443 \ -p 2222:22 \ casaos/casaos-docker -------------------------------------------------------------------------------------------------------------------------------- -------------------------------------docker上---mysql部署---------------------------------------------------------------- sudo docker pull mysql sudo docker run \ --name mysqlzz1 \ --hostname mysqlhost \ -p 3306:3306 \ -p 33060:33060 \ --env MYSQL_ROOT_PASSWORD=Yiyeshu@1 \ -v /home/$USER/containers/mysql/conf.d:/etc/mysql/conf.d \ -v /home/$USER/containers/mysql/data:/var/lib/mysql \ -v /home/$USER/containers/mysql/log:/var/log/mysql \ -d mysql 注意容器启动的mysql在连接的时候得加上-h参数注意容器映射的host地址:mysql -h x.x.x.x -uroot -p -------------------------------------------------------------------------------------------------------------------------- -------------------------------------docker上---nginx部署----------------------------------------------------------------------- sudo docker pull nginx sudo docker run -p 80:80 -p 443:443 --name nginx \ -v /home/$USER/nginxsite/html:/usr/share/nginx/html \ -v /home/$USER/nginxsite/ssl:/usr/share/nginx/ssl \ -v /home/$USER/nginxsite/log:/var/log/nginx \ -v /home/$USER/nginxsite/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /home/$USER/nginxsite/conf/conf.d:/etc/nginx/conf.d \ -d nginx html目录为index.html主页存放位置 ssl是自己建的用来存放ssl证书 log目录映射nginx日志 nginx.conf和conf.d里边的default.conf是nginx服务配置文件(由于映射目录会覆盖容器的对应目录,所以default.conf需要先拷贝到本机) 访问0.0.0.0:80查看结果 若显示404 sudo docker exec -it ... /bin/bash 进容器/usr/share/nginx/创建html目录把index.html放进去 ------------------------------------------------------------------------------------------------------------------------- -------------------------------------docker上---wordpress + mysql 部署---------------------------------------------------- sudo docker pull wordpress sudo docker pull mysql sudo docker network create network-wordpress sudo docker run \ --name dbwordpress \ --env MYSQL_ROOT_PASSWORD=123Zh456 \ --env MYSQL_DATABASE=dbwordpress \ -v /home/$USER/nginxsite/mysql/conf.d:/etc/mysql/conf.d \ -v /home/$USER/nginxsite/mysql/data:/var/lib/mysql \ -v /home/$USER/nginxsite/mysql/log:/var/log/mysql \ --network network-wordpress \ -d mysql sudo docker run \ --name wordpress \ -p 8099:80 \ -v /home/$USER/nginxsite/wordpress:/var/www/html \ --network network-wordpress \ -d wordpress +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 在参数中指定如下数据库信息似乎无效,只能到wordpress容器中修改wp-config.php --env WORDPRESS_DB_HOST=dbwordpress \ --env WORDPRESS_DB_NAME=dbwordpress \ --env WORDPRESS_DB_USER=root \ --env WORDPRESS_DB_PASSWD=123Zh456 \ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ over,访问0.0.0.0:8099页面会转到wordpress安装页面,按提示操作即可。 ----------------------------------------------------------------------------------------------------------------------- -------------------------------------docker上----tomcat部署------------------------------------------------------------ sudo docker pull tomcat docker run -p 8080:8080 \ -v /path/on/host:/usr/local/tomcat/webapps/ROOT \ tomcat ----------------------------------------------------------------------------------------------------------------------- -----------------------------------docker上------nginx转发tomcat部署---------------------------------------------------- sudo docker network create --driver bridge --subnet 172.18.0.0/16 --gateway 172.18.0.1 ngcat docker run -p 8080:8080 --name tomcat\ -v /home/zz/tomcatsite/webapps:/usr/local/tomcat/webapps/ \ --network ngcat \ -d tomcat 浏览器访问http://0.0.0.0:8080看到tomcat主页了。 sudo docker run -p 80:80 -p 443:443 --name nginx \ -v /home/$USER/nginxsite/html:/usr/share/nginx/html \ -v /home/$USER/nginxsite/ssl:/usr/share/nginx/ssl \ -v /home/$USER/nginxsite/log:/var/log/nginx \ -v /home/$USER/nginxsite/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /home/$USER/nginxsite/conf/conf.d:/etc/nginx/conf.d \ --network ngcat \ -d nginx 浏览器访问https://0.0.0.0看到nginx主页了。 sudo docker network inspect ngcat查看tomcat的ip地址为172.18.0.3 nginx配置文件default.conf中加入转发规则 location /tomcat/ { proxy_pass http://172.18.0.3:8080/; charset utf-8; } 浏览器访问https://0.0.0.0/tomcat/发现已经转发到tomcat主页了,以后的webapp的war包开发完直接撂到webapps目录里就可以访问了,over。 ------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------rabbitmq部署---------------------------------------------------------------------- sudo docker pull rabbitmq:management sudo docker run --name rabbitmq -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 25672:25672 -p 15671:15671 -p 15672:15672 -d rabbitmq:management 浏览器访问登陆页面默认账号密码都是guest,http://0.0.0.0:15672/ ------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------zookeeper部署---------------------------------------------------------------------- sudo docker pull wurstmeister/zookeeper sudo docker run --name zookeeper -p 2181:2181 -d wurstmeister/zookeeper ------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------kafka部署---------------------------------------------------------------------- docker-compose.yaml version: '3' services: zookeeper: image: wurstmeister/zookeeper ports: - "2181:2181" kafka: image: wurstmeister/kafka ports: - "9092:9092" environment: KAFKA_ADVERTISED_HOST_NAME: localhost KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 volumes: - /var/run/docker.sock:/var/run/docker.sock ------------------------------------------------------------------------------------------------------------------------------------