-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose-update-all.sh
41 lines (26 loc) · 1.08 KB
/
docker-compose-update-all.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
# lock script to prevent parallel execution
[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :
export LOG_LEVEL=error
docker image prune --all --force
# pull all images
for image in $(docker images --format "{{.Repository}}:{{.Tag}}" | grep -v '<none>'); do
docker pull $image --quiet
done
# Get list of all running containers
containerList=$(docker ps --quiet --all)
if [[ -n $containerList ]]; then
# Get compose files of the containers
configFileList=$(docker inspect $containerList --format '{{index .Config.Labels "com.docker.compose.project.config_files"}}' | sort | uniq)
# Iterate through running docker compose files
for configFile in $configFileList; do
# skip non existing files
[ -f "$configFile" ] || continue
projectDirectory="$(dirname $configFile)"
# skip ignored project directories
[ -f "$projectDirectory/.dockerupdateignore" ] && continue
# restart container
docker compose --project-directory "$projectDirectory" up --detach --remove-orphans
done
fi
docker image prune --all --force