-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocompose.sh
executable file
·44 lines (36 loc) · 1.18 KB
/
autocompose.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
42
43
44
#!/bin/bash
# This script makes use of [Auto-Compose](https://github.com/Red5d/docker-autocompose)
# Auto-Compose is not updated and may generate mistakes, but is generally helpful in converting running containers to compose files
help() {
cat << EOF
Use: autocompose.sh [options] [container_names]
This script creates a compose.yml file from running Docker containers using AutoCompose by Red5d
Options:
-a Auto-Compose all containers
-f Specify compose file path and name
-h Display this help dialog
AutoCompose source code: https://github.com/Red5d/docker-autocompose
EOF
}
# No arguments
if [ -z "$1" ]; then help; exit 1; fi
# Options
## Defaults
file=compose.auto.yml
## Flags
while getopts "af:h" opt; do
case ${opt} in
a ) all=true ;;
f ) file=$OPTARG ;;
h ) help; exit 2 ;;
? ) help; exit 1 ;;
esac
done
shift "$((OPTIND-1))"
# Selected containers to auto-compose
containers=$@
[ ! -z $all ] && containers=$(docker ps -aq)
# Run autocompose
docker run --rm --name autocompose \
-v /var/run/docker.sock:/var/run/docker.sock \
ghcr.io/red5d/docker-autocompose $containers > $file