summaryrefslogtreecommitdiff
path: root/start_container.sh
diff options
context:
space:
mode:
authorYour Name <you@example.com>2025-12-29 18:28:13 +0800
committerYour Name <you@example.com>2025-12-29 18:28:13 +0800
commit214f4bab8b852e9b66d909bc22e5f9119da7dfb5 (patch)
treeee970b0f1738e5e08afe24247305be2defb27735 /start_container.sh
initial commit
Diffstat (limited to 'start_container.sh')
-rwxr-xr-xstart_container.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/start_container.sh b/start_container.sh
new file mode 100755
index 0000000..bf1c167
--- /dev/null
+++ b/start_container.sh
@@ -0,0 +1,37 @@
1#!/bin/bash
2set -e
3
4# Load config
5source "$(dirname "$0")/config.env"
6
7# Create network if not exists
8if ! podman network exists ${NETWORK}; then
9 echo "Creating network: ${NETWORK} (subnet: ${PRIVATE_SUBNET})"
10 podman network create --subnet=${PRIVATE_SUBNET} ${NETWORK}
11else
12 echo "Network exists: ${NETWORK}"
13fi
14
15# Stop existing container if running
16podman stop ${CONTAINER_NAME} 2>/dev/null || true
17podman rm ${CONTAINER_NAME} 2>/dev/null || true
18ip route del ${PUBLIC_IP}/32 2>/dev/null || true
19
20# Run container
21podman run -d \
22 --name ${CONTAINER_NAME} \
23 --network ${NETWORK} \
24 --ip ${PRIVATE_IP} \
25 --cap-add=NET_ADMIN \
26 --env-file "$(dirname "$0")/config.env" \
27 -v ${CONTAINER_NAME}_data:/data \
28 -v /git:/git \
29 localhost/cgit-caddy
30
31# Setup public IP
32sleep 2
33IFACE=$(podman exec ${CONTAINER_NAME} sh -c "ip -o link | grep -v lo | head -1 | cut -d: -f2 | tr -d ' ' | cut -d@ -f1")
34podman exec ${CONTAINER_NAME} ip addr add ${PUBLIC_IP}/32 dev ${IFACE}
35ip route add ${PUBLIC_IP}/32 via ${PRIVATE_IP}
36
37echo "Running at https://${DOMAIN}/"