本帖最后由 hugh_jie 于 2023-10-24 18:19 编辑
最近迁移系统,感觉一个个弄有点零碎,虽然很简单,但是毕竟需要一个个pull-run,复制配置文件等等,有点麻烦
整理了一下,使用docker-compose节省了手动pull和run的时间,记录一下顺便分享一下
只弄了ha、nodered、esphome、mpd、zigbee2mqtt、portainer、ddns-go 7个
其他必须的比如mosquitto、nginx,非必须的mysql我是直接部署在系统里的,略
下面正式开始
docker部署
curl -fsSL https://get.docker.com/ | sh
等待完成后添加镜像加速
vim /etc/docker/daemon.conf
添加内容:
{
"registry-mirrors" : [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://cr.console.aliyun.com",
"https://mirror.ccs.tencentyun.com"
]
}
重启docker
systemctl restart docker
docker-compose
安装
curl -L https://github.com/docker/compose/releases/download/2.23.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
两行代码分别执行,第一行代码下载太慢的话手动去下载后放入/usr/local/bin目录
然后执行第二行
完成后可以使用`docker-compose --version`查看是否成功
容器部署
- 提前创建数据卷
docker volume create esphome
docker volume create ddns_go
docker volume create homeassistant
docker volume create mpd
docker volume create nodered
docker volume create portainer
docker volume create zigbee2mqtt
- 创建docker-compose.yml文件,记住在哪儿创建的
services:
ESPHome:
container_name: "ESPHome"
image: "esphome/esphome:latest"
network_mode: "host"
restart: "always"
volumes:
- "esphome:/config"
ddns-go:
container_name: "ddns-go"
environment:
- "TZ=Asia/Shanghai"
image: "jeessy/ddns-go:latest"
network_mode: "host"
restart: "always"
volumes:
- "ddns_go:/root"
homeassistant:
container_name: "homeassistant"
environment:
- "TZ=Asia/Shanghai"
image: "docker.io/homeassistant/home-assistant:latest"
network_mode: "host"
privileged: true
restart: "always"
volumes:
- "homeassistant:/config"
mpd:
container_name: "mpd"
devices:
- "/dev/snd:/dev/snd"
image: "schumyhao/mpd:latest"
network_mode: "host"
restart: "always"
volumes:
- "/var/lib/docker/volumes/mpd:/var/lib/mpd"
- "/var/lib/docker/volumes/mpd/database:/var/lib/mpd/database"
- "/var/lib/docker/volumes/mpd/mpd.conf:/etc/mpd.conf"
- "/var/lib/docker/volumes/mpd/mpd.log:/var/lib/mpd/mpd.log"
- "/var/lib/docker/volumes/mpd/music:/var/lib/mpd/music"
- "/var/lib/docker/volumes/mpd/playlists:/var/lib/mpd/playlists"
- "/var/lib/docker/volumes/mpd/state:/var/lib/mpd/state"
- "/var/lib/docker/volumes/mpd/sticker.sql:/var/lib/mpd/sticker.sql"
nodered:
container_name: "nodered"
environment:
- "TZ=Asia/Shanghai"
image: "nodered/node-red:latest"
network_mode: "host"
restart: "always"
volumes:
- "nodered:/data"
portainer:
container_name: "portainer"
image: "6053537/portainer-ce:latest"
network_mode: "bridge"
ports:
- "9000:9000/tcp"
- "8000:8000"
restart: "always"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "portainer:/data"
zigbee2mqtt:
container_name: "zigbee2mqtt"
environment:
- "TZ=Asia/Shanghai"
image: "docker.io/koenkk/zigbee2mqtt:latest-dev"
network_mode: "host"
restart: "always"
volumes:
- "/var/lib/docker/volumes/zigbee2mqtt/data:/app/data"
version: "3.6"
volumes:
ddns_go:
external: true
portainer:
external: true
esphome:
external: true
homeassistant:
external: true
nodered:
external: true
- mpd需要提前创建文件和文件夹
cd /var/lib/docker/volumes/mpd
mkdir music playlists
touch database mpd.log mpd.pid state sticker.sql
vim mpd.conf
mpd.conf内容
music_directory "/var/lib/mpd/music"
playlist_directory "/var/lib/mpd/playlists"
db_file "/var/lib/mpd/database"
log_file "/var/lib/mpd/mpd.log"
pid_file "/var/lib/mpd/mpd.pid"
state_file "/var/lib/mpd/state"
sticker_file "/var/lib/mpd/sticker.sql"
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:1,0"
mixer_type "software"
}
这里使用的device是usb声卡,hw后面两个数字分别是card,device,使用`aplay -l`查看声卡,按需修改
4. 启动docker-compose:在创建docker-compose.yml文件的目录
5. 全部变成running后`ctrl + c`退出,容器会全部停止
6. 修改zigbee2mqtt配置文件configuration.yaml
homeassistant: true
permit_join: false
mqtt:
base_topic: zigbee2mqtt
server: mqtt://192.168.xx.xx //mqtt服务器地址
user: mqtt //mqtt服务器用户名。密码
password: 'xxxxxxx'
serial:
port: tcp://192.168.xxx.xx:1024 //我的是用的无线,有线自行修改
7. 完成后执行`docker-compose start`启动,到这一步容器基本上都能运行了,只差配置文件了,自行解决~
有些系统默认不会开放端口,比如centos,手动开启一下
firewall-cmd --zone=public --add-port=8123/tcp --permanent
firewall-cmd --zone=public --add-port=1880/tcp --permanent
firewall-cmd --zone=public --add-port=6052/tcp --permanent
firewall-cmd --zone=public --add-port=9000/tcp --permanent
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --reload
|