zscripts-token-savers/bash/zstart_docker
KellyMichels 8e6ffea1a4 feat(bash): native bash port of all z-scripts for Linux/macOS/WSL
Full port: zhelpers.sh library (jq config, ssh, http/tcp, archive builder,
build-version, motd, port-kill), all commands (zstart/zkill/zrestart/zstop,
zdeploy with 5 kind handlers, zec2/zec2online/zrepair, zbackup/zbackup_ec2/
zsync/zbackup_and_sync, zstart_docker, zsetup_mail, setup_backup_schedule via
cron), Unix-path zconfig.example.json, and a bash/README.md.

Verified: bash -n clean on all scripts; archive exclusions, config semantics,
and zec2 tested against the real config and live server from Git Bash. Needs a
Linux/macOS/WSL shakedown for lsof/rsync/nohup paths before merging.
2026-07-16 14:07:02 -05:00

66 lines
2.0 KiB
Bash

#!/usr/bin/env bash
# Evomedia.net Token Savers — https://github.com/kellymichels/zscripts-token-savers
# Created by Kelly Michels · dev@evomedia.net
# Licensed under the MIT License. See LICENSE.
#
# zstart_docker — bring up a local docker compose stack from <scriptsRoot>/docker/.
#
# Usage:
# zstart_docker [--build] [--attached] [--solo]
#
# --build rebuild images before starting
# --attached stream logs in the foreground (default is detached)
# --solo use docker-compose.solo.yml (app only, no proxy)
set -uo pipefail
_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$_HERE/zhelpers.sh"
z_require docker
build=0; attached=0; solo=0
while [ $# -gt 0 ]; do
case "$1" in
--build) build=1; shift ;;
--attached) attached=1; shift ;;
--solo) solo=1; shift ;;
*) err "Unknown option: $1"; exit 1 ;;
esac
done
info "=== zstart_docker ==="
compose_file="docker-compose.yml"
[ "$solo" -eq 1 ] && compose_file="docker-compose.solo.yml"
if ! docker info >/dev/null 2>&1; then
printf '\n'
err "ERROR: Docker Engine is not running or this shell cannot reach it."
printf '\n'
info "Try:"
dim " 1. Start the Docker daemon (systemctl start docker / open Docker Desktop)."
dim " 2. Check your user is in the docker group: groups | grep docker"
printf '\n'
exit 1
fi
compose_path="$_HERE/docker/$compose_file"
if [ ! -f "$compose_path" ]; then
err "ERROR: Missing $compose_path"
exit 1
fi
[ -f "$_HERE/.env" ] || warn "WARNING: .env not found at $_HERE/.env - compose may still start if env vars are set elsewhere."
dc_args=(compose -f "$compose_file" up)
[ "$attached" -eq 0 ] && dc_args+=(-d)
[ "$build" -eq 1 ] && dc_args+=(--build)
dim "Running: docker ${dc_args[*]}"
(cd "$_HERE/docker" && docker "${dc_args[@]}") || exit $?
printf '\n'; ok "Stack: http://localhost/"
if [ "$attached" -eq 0 ]; then
dim 'Logs: docker compose -f docker/docker-compose.yml logs -f'
dim 'Stop: docker compose -f docker/docker-compose.yml down'
fi