Open notfol opened 6 years ago
This doesn't seem to work when executing commands on swarm task containers running on a different docker host than docker-crontab.
docker-crontab
below assumes the container is running on the same host
CONTAINERS=$(docker ps --format '{{.Names}}' | grep -E "^[project]_[alias].[0-9]+") for CONTAINER_NAME in $CONTAINERS; do docker exec ${CONTAINER_NAME} [command] done
You could do something like below to get the container name from the docker host running the swarm task.
# deploy {ca,cert,key}.pem as secrets function set_docker_env { export DOCKER_CERT_PATH=/run/secrets export DOCKER_HOST=tcp://$1:2376 export DOCKER_TLS_VERIFY=1 } function unset_docker_env { unset DOCKER_CERT_PATH unset DOCKER_HOST unset DOCKER_TLS_VERIFY } function container_host_from_docker { docker service ps --format '{{.Node}}' --filter 'desired-state=running' $1 | head -n 1 } function container_name_from_docker { set_docker_env $1 docker ps --format '{{.Names}}' | grep -E "^$2.[0-9]+" | head -n 1 } CONTAINER_HOST=$( container_host_from_docker [project]_[alias] ) if [ ! -z "${CONTAINER_HOST// }" ] then CONTAINER_NAME=$( container_name_from_docker $CONTAINER_HOST [project]_[alias] ) docker exec ${CONTAINER_NAME} [command] fi unset_docker_env
Just noticed this is your to-do's :) I might submit a PR
Looking forward to it.
This doesn't seem to work when executing commands on swarm task containers running on a different docker host than
docker-crontab
.below assumes the container is running on the same host
You could do something like below to get the container name from the docker host running the swarm task.