我有三个容器:
该应用程序是一个IOT应用程序,我想从我的核心容器中扫描可用的wifi网络。
version: "3"
services:
watchtower:
container_name: watchtower
image: talmai/rpi-watchtower
env_file:
- watchtower.env
volumes:
- /run/docker.sock:/var/run/docker.sock
mongo:
ports:
- "27017:27017"
- "27018:27018"
container_name: mongo
volumes:
- ".tmp/mongo/data:/data/db"
- ".tmp/backup:/data/backup"
image: iotapp/iotapp_mongo:latest
networks:
- backend
iotapp_gui:
ports:
- "80:80"
container_name: iotapp_gui
depends_on:
- "iotapp_core"
image: iotapp/iotapp_gui:latest
networks:
- frontend
iotapp_core:
ports:
- "3000:3000"
env_file:
- core.env
container_name: iotapp_core
depends_on:
- "mongo"
privileged: true
volumes:
- ".tmp/logs:/data/logs"
- ".tmp/backup:/data/backup"
- "/etc/wpa_supplicant:/etc/wpa_supplicant"
- "/etc/default/hostapd:/etc/default/hostapd"
image: iotapp/iotapp_core:latest
networks:
- backend
- frontend
network_mode: host
networks:
backend:
driver: bridge
frontend:
driver: bridge
我的问题是使主机网络可用于核心容器。到目前为止我尝试过
driver: host
=>定义网络=仅允许“主机”网络的一个实例networks
容器上使用network_mode: host
和core
=> 'network_mode' and 'networks' cannot be combined
network_mode: host
=> mongo
不再可以访问问题:
如何使网络可用,但仍然让核心与其他容器通信?
答案 0 :(得分:0)
我使用Linux命名管道在主机和容器之间进行通信。主机在启动时创建一个命名管道,该管道具有循环以查询wifi SSID。管道的文件夹与docker容器共享。然后,docker容器查询管道:
wifi.pipe(在后台启动时运行):
#!/bin/bash
pipePath="/home/pi/app/pipes/wifi.pipe"
if [[ ! -p $pipePath ]]; then
mkfifo $pipePath
fi
while true; do iwlist wlan0 scan | grep ESSID > $pipePath; done
在Docker容器内部:
cat < /pipes/wifi.pipe
Docker撰写:
...
volumes:
- "/home/pi/app/pipes:/pipes"
...