Skip to content

Instantly share code, notes, and snippets.

@happyincent
Created June 10, 2019 14:23
Show Gist options
  • Save happyincent/45891c1b75e12aea551b1cd722864d88 to your computer and use it in GitHub Desktop.
Save happyincent/45891c1b75e12aea551b1cd722864d88 to your computer and use it in GitHub Desktop.
Mount Arduino Serial, Use Host network in Docker Swarm
version: '3'
networks:
docker_host:
external:
name: 'host'
services:
docker-parent:
image: docker:latest
command:
- "/bin/sh"
- -c
- |
trap "docker rm -f docker-child" SIGTERM
echo "Init work ..."
docker rm -f docker-child
docker rmi alpine:latest
if [[ -z $$SERIAL_PORT ]]; then \
docker run --name=docker-child \
--net=host \
alpine:latest \
ping -c3 $$HOSTNAME && tail -f /dev/null &
else
docker run --name=docker-child \
--net=host \
--device=$$SERIAL_PORT \
alpine:latest \
sh -c "ping -c3 $$HOSTNAME > $$SERIAL_PORT && tail -f /dev/null" &
fi
CHILD=$$!
echo "Wait for $$CHILD ..."
wait $$CHILD
echo "Exit ..."
environment:
SERIAL_PORT: /dev/ttyACM0
HOSTNAME: RPi0
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- 'docker_host'
deploy:
replicas: 1
restart_policy:
condition: any
delay: 30s
placement:
constraints:
- node.hostname == RPi0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment