Docker Compose 업데이트 스크립트

Sun Mar 31, 2024
1 minute to read

각 컨테이너의 com.docker.compose.project.working_dir를 가져와 업데이트한다.

 1#!/bin/bash
 2
 3# Unofficial Bash Strict Mode
 4# http://redsymbol.net/articles/unofficial-bash-strict-mode/
 5set -euo pipefail
 6IFS=$'\n\t'
 7# End of Unofficial Bash Strict Mode
 8
 9for container_id in $(docker ps -q); do
10    working_dir=$(docker inspect $container_id --format '{{ index .Config.Labels "com.docker.compose.project.working_dir" }}')
11
12    echo "$container_id: $working_dir"
13
14    if [ -z "$working_dir" ]; then
15        printf "Container is not managed with docker-compose.\n\n"
16        continue
17    fi
18
19    cd "$working_dir"
20
21    docker-compose pull
22    docker-compose up -d
23
24    printf "\n"
25done