How to update docker service using a version from docker-compose
Here is a small script which compares the version of the running service and the version in the docker-compose file, if they are different it runs an update.
REDIS_VERSION=$(docker service ls | grep "redis" | awk '{print $5}')
REDIS_NEW_VERSION=$(grep -Po "image:\s*\Kredis:.*" docker-compose.yml)
if [ "$REDIS_VERSION" != "$REDIS_NEW_VERSION" ]; then
echo "update $REDIS_VERSION -> $REDIS_NEW_VERSION"
docker service update --image $REDIS_NEW_VERSION app_redis
fi