From 83091962a263a91231b5c68cb3c62fce80a3df00 Mon Sep 17 00:00:00 2001 From: sujiba Date: Tue, 7 May 2024 00:42:02 +0200 Subject: [PATCH] chore: layout changes --- README.md | 17 +++++++++++++++++ container-update.sh | 31 +++++++++++++++++++++++++++++++ home_stack/docker-compose.yml | 4 ++-- homepage/docker-compose.yml | 2 +- nextcloud/docker-compose.yml | 19 +++++++++---------- template/docker-compose.yml | 20 ++++++++++++++++++-- 6 files changed, 78 insertions(+), 15 deletions(-) create mode 100644 container-update.sh diff --git a/README.md b/README.md index c7f3aa4..f334ae3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ # docker-compose +- [docker-compose](#docker-compose) + - [Directory structure](#directory-structure) + +## Directory structure +``` +/opt/docker +. +├── container-update.sh +├── example_stack +│   ├── docker-compose.yml +│   └── volumes +└── example_app +    ├── docker-compose.yml +    ├── docker-compose.yml_bak +    └── volumes +``` + diff --git a/container-update.sh b/container-update.sh new file mode 100644 index 0000000..6bd37e0 --- /dev/null +++ b/container-update.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -e + +for compose_file in /opt/docker/**/docker-compose.yml; do + if [[ $(docker compose -f "$compose_file" ps -q) ]]; then + echo "> Updating $compose_file" + docker compose -f "$compose_file" pull + docker compose -f "$compose_file" up -d --remove-orphans + echo "" + else + echo "> Skipping $compose_file as it's not running." + echo "" + fi +done + +echo "> Containers have been updated." +echo "" + +confirm=n +read -p "> Do you want to remove all dangling images? [y/N]" confirm +echo "" + +if [[ $confirm == [yY] ]]; then + docker image prune -f -a + echo "> All dangling images have been removed." +else + echo "> Dangling images haven't been removed." +fi + +exit diff --git a/home_stack/docker-compose.yml b/home_stack/docker-compose.yml index 39ace74..f3887e7 100644 --- a/home_stack/docker-compose.yml +++ b/home_stack/docker-compose.yml @@ -17,7 +17,7 @@ services: group_add: - dialout ports: - - 127.0.0.1:38080:8080 + - "127.0.0.1:38080:8080" volumes: - ./volumes/zigbee2mqtt/data:/app/data - /run/udev:/run/udev:ro @@ -33,7 +33,7 @@ services: container_name: mqtt command: "mosquitto -c /mosquitto-no-auth.conf" ports: - - 127.0.0.1:1883:1883 + - "127.0.0.1:1883:1883" volumes: - ./volumes/mosquitto/conf:/mosquitto/conf - ./volumes/mosquitto/data:/mosquitto/data diff --git a/homepage/docker-compose.yml b/homepage/docker-compose.yml index 29f397d..dc10dd8 100644 --- a/homepage/docker-compose.yml +++ b/homepage/docker-compose.yml @@ -8,7 +8,7 @@ services: PGID: 1001 TZ: Europe/Berlin ports: - - 127.0.0.1:13000:3000 + - "127.0.0.1:13000:3000" volumes: - ./volumes/config:/app/config - ./volumes/icons:/app/public/icons diff --git a/nextcloud/docker-compose.yml b/nextcloud/docker-compose.yml index 32d3512..1a5a52b 100644 --- a/nextcloud/docker-compose.yml +++ b/nextcloud/docker-compose.yml @@ -4,9 +4,6 @@ services: image: mariadb:10.5 container_name: nc_db command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW - restart: unless-stopped - volumes: - - ./volumes/db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=Subatomic-Lapping0-Untagged-Deceptive-Judge - MARIADB_AUTO_UPGRADE=1 @@ -14,6 +11,9 @@ services: env_file: - mariadb.env - nextcloud.env + volumes: + - ./volumes/db:/var/lib/mysql + restart: unless-stopped nc_redis: image: redis:alpine @@ -23,11 +23,6 @@ services: nc_app: image: nextcloud:apache container_name: nc_app - restart: unless-stopped - volumes: - - ./volumes/nextcloud:/var/www/html - ports: - - "127.0.0.1:28080:80" environment: - MYSQL_HOST=nc_db - REDIS_HOST=nc_redis @@ -38,18 +33,22 @@ services: - PHP_UPLOAD_LIMIT=1G env_file: - nextcloud.env + ports: + - "127.0.0.1:28080:80" + volumes: + - ./volumes/nextcloud:/var/www/html depends_on: - nc_db - nc_redis + restart: unless-stopped nc_cron: image: nextcloud:apache container_name: nc_cron - restart: unless-stopped volumes: - ./volumes/nextcloud:/var/www/html entrypoint: /cron.sh depends_on: - nc_db - nc_redis - 54,1 Bot + restart: unless-stopped diff --git a/template/docker-compose.yml b/template/docker-compose.yml index 4da25f2..e39aa27 100644 --- a/template/docker-compose.yml +++ b/template/docker-compose.yml @@ -1,12 +1,28 @@ --- +name: app_stack services: - service_name: + foo: image: container_name: + command: environment: env_file: - command: ports: volumes: depends_on: restart: unless-stopped + + bar: + image: bar/bar:latest + container_name: bar + command: + environment: + - TZ=Europe/Berlin + env_file: + ports: + - "127.0.0.1:443:443" + volumes: + - ./volumes/bar:/bar + depends_on: + - foo + restart: unless-stopped