#!/bin/sh trap cleanup SIGTERM cleanup() { echo Terminating $SERVICENAME docker rm -f $(docker ps -q -f label=ru.sdsys.subcontainer=$SERVICENAME) } SERVICENAME=$(docker inspect $HOSTNAME -f "{{index .Config.Labels \"com.docker.swarm.service.name\"}}") echo Starting $SERVICENAME exec "docker" "run" "-l" "ru.sdsys.subcontainer=$SERVICENAME" "$@" & wait