我有一个Python应用程序,旨在在树莓派上运行。我已经创建了一个docker-compose文件来设置它,我的入口点恰好是一个shell脚本,它检查主机上的各种事情,例如:
- 确保启用SPI,如果没有启用,则通过访问/boot/config.txt并编写它来启用。
- 安装和启用看门狗服务。
- 通过将其写入/etc/rc.local来自动重新启动我的docker容器(尽管我正在考虑使用docker-compose文件中的restart: always或unless-stopped标志替换它)
Failed to connect to bus: No such file or directory
Failed to talk to init daemon.
我理解它可能正在尝试在Docker容器内查找DBus和init守护程序,但它们不存在。我该如何让我的容器访问这些资源?我需要挂载另一个卷吗?以下是我的docker-compose.yml文件:
version: "3"
services:
mongoDB:
restart: unless-stopped
volumes:
- "/data/db:/data/db"
ports:
- "27017:27017"
- "28017:28017"
image: "andresvidal/rpi3-mongodb3:latest"
mosquitto:
restart: unless-stopped
ports:
- "1883:1883"
image: "mjenz/rpi-mosquitto"
FG:
privileged: true
network_mode: "host"
depends_on:
- "mosquitto"
- "mongoDB"
volumes:
- "/home/pi:/home/pi"
- "/boot:/boot"
#image: "arkfreestyle/fg:v1.8"
image: "test:latest"
entrypoint: /app/docker-entrypoint.sh
restart: unless-stopped
FG是我的Python应用程序,入口点是docker-entrypoint.sh,它看起来像这样:
#!/bin/sh
if [ ! -f /home/pi/.initialized ]; then
echo "Initializing..."
# Turn spi on
if grep -Fxq "dtparam=spi=on
dtparam=watchdog=on" /boot/config.txt
then
echo "\nSPI is already enabled"
echo "Creating .initialized"
# Create .initialized hidden file
touch /home/pi/.initialized
echo "Starting application..."
sudo python3 __main__.py -debug
else
### Enable SPI ###
fi
fi
### Create .initialized file ###
echo "Rebooting in ten seconds..."
sleep 10
sudo reboot # This line results in the error
else
echo "Initialized already!"
sudo python3 __main__.py -debug
fi
特权选项已经让我的容器可以访问GPIO,我本以为它也可以让我重启,但是似乎不是这样的。请告诉我需要做什么才能重新启动。
--pid=host
的情况下使其工作。很高兴对你来说结果变得更简单了! - larsks