A docker compose enhanced tool.
Base on docker/compose v2.12.2, Follow official updates unscheduled.
-
HOOKs: Executing commands
- Hook
docker compose up
- Hook
docker compose down
- Command supports:
- CLI
- the code of Shell in the docker-compose.yml
- Hook
-
Copy file/folder from the image to the local filesystem.
$ cd /this/project/cmd
$ go build -ldflags "-X github.com/docker/compose/v2/internal.Version=2.12.2.2" -o docker-compose
Copy the release to
$ wget https://github.com/fly-studio/docker-compose/releases/download/v2.12.2.2/docker-compose -O /usr/libexec/docker/cli-plugins/docker-compose
$ chmod +x /usr/libexec/docker/cli-plugins/docker-compose
And copy or symlink to /usr/bin
$ cp /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose
docker compose [OPTIONS] deploy [SERVICE...] [OPTIONS_OF_UP] [--hook]
Creating and starting containers with HOOKs, the usage is similar to docker compose up.
Name | Default | Description |
---|---|---|
[OPTIONS] | The options of docker compose --help | |
[SERVICE...] | The list of services that you want to up |
|
[OPTIONS_OF_UP] | The options of docker compose up --help | |
--hook | false | Enable executing commands before/after up |
docker-compose.yml
Name | Types | Description |
---|---|---|
x-hooks | ||
- pre-deploy | Array | CLI, shell-key |
- post-deploy | Array | CLI, shell-key |
- Hooks
- Copy the config files from the image of 'nginx'
- Create a config file to /local/nginx/conf.d/vhosts.conf
- Mount the path of config to container of 'nginx'
docker-compose.yml
x-hooks: # Global
pre-deploy:
- ["echo", "global pre-deploy"]
post-deploy:
- ["echo", "global post-deploy"]
services:
nginx:
image: nginx:latest
volumes:
- /local/nginx/:/etc/nginx/
x-hooks: # Scoped
pre-deploy:
- ["mkdir", "-p", "/local/nginx/conf.d/vhosts"]
- ["docker", "compose", "cpi", "nginx", "/etc/nginx/:/local/"]
- ["sh", "-c", "echo 'include conf.d/vhosts/*.conf;' > /local/nginx/conf.d/vhosts.conf"]
post-deploy:
- ["echo", "scoped post-deploy"]
Deploy
$ docker-compose deploy --hook -d
- Global pre-deploy
- pre-deploy of each service of [SERVICE...]
- Up
- post-deploy of each service of [SERVICE...]
- Global post-deploy
$ docker -f /a/b/docker-compose.yml deploy --hook
-
Working directory is the directory of
docker-compose.yaml
, eg:/a/b/
-
Path in the command is relative to the directory of
docker-compose.yaml
- ["sh", "-c", "echo 'xxx' >> scripts/main.txt"
the real path of scripts/main.txt
is /a/b/scripts/main.txt
Execute Shell from x-key
["shell-key", "x-key"]
Execute Shell file
["sh", "/path/to/file.sh"]
Specify any arguments to shell-key
["shell-key", "x-key", "--argument1", "value1", "--argument2"]
See examples/docker-compose.yaml
docker compose [OPTIONS] undeploy [SERVICE...] [OPTIONS_OF_DOWN] [--hook]
Stopping containers with HOOKs, the usage is similar to docker compose down.
Name | Default | Description |
---|---|---|
[OPTIONS] | The options of docker compose --help | |
[SERVICE...] | The list of services that you want to down |
|
[OPTIONS_OF_DOWN] | The options of docker compose down --help | |
--hook | false | Enable executing commands before/after down |
docker-compose.yml
Name | Types | Description |
---|---|---|
x-hooks | ||
- pre-undeploy | Array | CLI, shell-key |
- post-undeploy | Array | CLI, shell-key |
- Global pre-undeploy
- pre-undeploy of each service of [SERVICE...]
- Down
- post-undeploy of each service of [SERVICE...]
- Global post-undeploy
docker-compose.yml
services:
nginx:
x-hooks:
post-undepoly:
- ["rm", "-rf", "/local/nginx"]
Undeploy
$ docker-compose undeploy nginx --hook
docker compose [OPTIONS] cpi [SERVICE] [PATH_IN_IMAGE:LOCAL_PATH...] [--follow-link]
Copy a file/folder from the image of the SERVICE to the local filesystem
Name | Description |
---|---|
[OPTIONS] | The options of docker compose --help |
[SERVICE] | The service name that you want to copy from |
[PATH_IN_IMAGE:LOCAL_PATH...] | Array |
· PATH_IN_IMAGE | The source path in the image of the [SERVICE] |
· LOCAL_PATH | The destination path of local filesystem |
--follow-link -L |
Always follow symbol link in [PATH_IN_IMAGE] |
- Can be a DIRECTORY when
PATH_IN_IMAGE
is a file or directory - Can be a FILE when
PATH_IN_IMAGE
is a file - The base directory of
LOCAL_PATH
MUST exist
PATH_IN_IMAGE | LOCAL_PATH folder | LOCAL_PATH file |
---|---|---|
folder | √ | × |
file | √ | √ |
$ mkdir -p /local/nginx/ ## path must exist ##
$ docker compose -f "/a/b/docker-compose.yaml" cpi nginx \
/etc/nginx/conf:/local/nginx/ \
/etc/resolve.conf:/local/resolve.conf