Skip to content

Instantly share code, notes, and snippets.

@arsalanses
Created October 31, 2024 09:03
Show Gist options
  • Save arsalanses/2f4a698c24371eebad50f95e0d91eb9c to your computer and use it in GitHub Desktop.
Save arsalanses/2f4a698c24371eebad50f95e0d91eb9c to your computer and use it in GitHub Desktop.
docker swarm config service update
#!/bin/bash
set -xue
OLD_CONFIG=$(docker service inspect service_name | jq .[].Spec.TaskTemplate.ContainerSpec.Configs[].ConfigName)
OLD_VERSION=${OLD_CONFIG: -2:-1}
NEW_VERSION=$((OLD_VERSION + 1))
NEW_CONFIG=$(echo "$OLD_CONFIG" | sed "s/$OLD_VERSION/$NEW_VERSION/")
echo "NEW_CONFIG: $NEW_CONFIG"
docker config create ${NEW_CONFIG:1:-1} ./.env
docker service update --config-rm ${OLD_CONFIG:1:-1} --config-add source=${NEW_CONFIG:1:-1},target=/app/.env service_name
# docker service inspect service_name | jq .[].Spec.TaskTemplate.ContainerSpec.Configs[].ConfigName
# docker config rm env_config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment