| title | Cheat sheet |
|---|
import AsciinemaPlayer from "../../src/components/AsciinemaPlayer";
containers:
my-container:
image: alpine:3.11.3
tasks:
say-hello:
description: Say hello to the nice person reading the Batect documentation
run:
container: my-container
command: echo 'Hello world!'containers:
my-container:
image: alpine:3.11.3
command: echo "Hello world"Reference: containers
containers:
my-container:
# ...other config
command: echo "Hello world"Reference: command
containers:
my-container:
# ...other config
working_directory: /my/working/dirReference: working_directory
containers:
my-container:
# ...other config
environment:
MY_ENVIRONMENT_VARIABLE: "the value"Reference: environment
Mount the project directory into the container at /code:
containers:
my-container:
# ...other config
volumes:
- local: .
container: /codeReference: volumes
containers:
my-container:
image: alpine:3.11.3Reference: image
Use the Dockerfile from the images/my-container directory:
containers:
my-container:
build_directory: images/my-containerReference: build_directory
containers:
my-container:
build_directory: images/my-container
build_args:
MY_BUILD_ARG: "some value"Reference: build_args
Use the file AnotherDockerfile from the images/my-container directory:
containers:
my-container:
build_directory: images/my-container
dockerfile: AnotherDockerfileReference: dockerfile
tasks:
my-task:
run:
container: my-containerReference: tasks
tasks:
my-task:
run:
container: my-container
command: echo 'Hello there!'Reference: command
tasks:
my-task:
run:
container: my-container
working_directory: /some/other/directoryReference: working_directory
tasks:
my-task:
run:
container: my-container
environment:
MY_ENVIRONMENT_VARIABLE: "the value"Reference: environment
tasks:
my-task:
run:
container: my-container
ports:
- local: 8080
container: 8080Reference: ports
This can be configured in two ways: on the container, or on a per-task basis.
To specify that a container must always start before another container:
containers:
my-container:
# ...other config
dependencies:
- other-containerTo specify that a container must start before the main task container for a single task:
tasks:
my-task:
run:
container: my-container
dependencies:
- other-containerReference: container: dependencies, task: dependencies
Batect will automatically use a health check defined in the container's image's Dockerfile:
FROM my-image:1.2.3
HEALTHCHECK --interval=2s --retries=10 CMD /tools/health-check.shAlternatively, specify the health check settings on the container:
containers:
my-container:
# ...other config
health_check:
command: /tools/health-check.sh
retries: 10
interval: 2sThe command must exit with a non-zero exit code when the container is not ready, and exit with a zero exit code when the container is ready.
Reference: HEALTHCHECK, health_check
containers:
my-container:
# ...other config
setup_commands:
- command: /tools/setup.shReference: setup_commands
tasks:
my-task:
dependencies:
- other-container
run:
container: my-container
customise:
other-container:
environment:
OVERRIDDEN_VAR: overridden value from task
NEW_VAR: new value from task
containers:
main-container:
image: ...
other-container:
image: ...
environment:
CONTAINER_VAR: set on container
OVERRIDDEN_VAR: won't be usedWhen the task my-task is run, other-container will start with the environment variables:
CONTAINER_VAR:set on containerOVERRIDDEN_VAR:overridden value from taskNEW_VAR:new value from task
Reference: customise
tasks:
my-task:
dependencies:
- other-container
run:
container: my-container
customise:
other-container:
ports:
- 3000:4000
containers:
main-container:
image: ...
other-container:
image: ...
ports:
- 1000:2000When the task my-task is run, other-container will start with container ports 2000 and 4000 exposed as ports 1000 and 3000 on the host machine.
Reference: customise
tasks:
my-task:
dependencies:
- other-container
run:
container: my-container
customise:
other-container:
working_directory: /customised
containers:
main-container:
image: ...
other-container:
image: ...
working_directory: /wont-be-usedWhen the task my-task is run, other-container will in /customised.
Reference: customise
tasks:
my-task:
prerequisites:
- my-other-task
run:
container: my-container
my-other-task:
# ...config for taskReference: prerequisites
containers:
my-container:
# ...other config
volumes:
- type: cache
name: my_cache
container: /caches/my_cache./batect --cleanReference: --clean
Use the --cache-type=directory option, or set the BATECT_CACHE_TYPE environment variable to directory:
./batect --cache-type=directory my-taskReference: --cache-type
./batect --disable-ports my-taskReference: --disable-ports
config_variables:
log_level:
description: Log level to use for application
default: debugReference: config_variables
Use an expression like <{log_level} on supported properties.
./batect --config-var log_level=warning my-taskReference: --config-var
Create a YAML file in variable_name: value format, for example:
log_level: warning
host: myawesomeapp.comThen use --config-vars-file to tell Batect to use that file:
./batect --config-vars-file=my-vars.yml my-taskBatect will automatically use config variables from a file called batect.local.yml if it exists and --config-vars-file is not specified.
Reference: --config-vars-file
Use an expression like $MY_ENVIRONMENT_VARIABLE on supported properties.
config_variables:
log_level:
description: Log level to use for application
default: debugThen use an expression like <{log_level} on supported properties.
Reference: config_variables
Use --output=all:
./batect --output=all my-taskThis produces output similar to the following:
<AsciinemaPlayer src={require("../assets/outputstyles/interleaved.cast").default} width={204} height={20} preload={true} poster="npt:4" />
Reference: --output
Use --no-cleanup, --no-cleanup-after-failure or --no-cleanup-after-success:
./batect --no-cleanup my-taskReference: --no-cleanup, --no-cleanup-after-failure and --no-cleanup-after-success
Mount the Docker daemon socket into the container, and then use the docker CLI tool like normal:
containers:
docker-env:
volumes:
- local: /var/run/docker.sock
container: /var/run/docker.sockNote that local settings like registry credentials will not be forwarded to the container - the container will need to be configured with these.
Use --docker-host (or set the DOCKER_HOST environment variable):
./batect --docker-host=unix:///var/run/other-docker.sockThis option accepts Unix sockets (on macOS and Linux), named pipes (on Windows) and TCP addresses (on all platforms).
Reference: --docker-host
If /my-project/a.yml contains:
containers:
my-container:
image: my-image:1.2.3
include:
- includes/b.ymlAnd /my-project/includes/b.yml contains:
tasks:
my-task:
run:
container: my-containerThen the resulting configuration is as if /my-project/a.yml was:
containers:
my-container:
image: my-image:1.2.3
tasks:
my-task:
run:
container: my-containerReference: include
include:
- type: git
repo: https://github.com/batect/hello-world-bundle.git
ref: 0.2.0Reference: include
This makes port 5678 on the container accessible at port 1234 on the host machine:
containers:
my-container:
# ...other config
ports:
- local: 1234
container: 5678Reference: ports
There is no configuration required to expose a port from a container to another container running in the same task.
Use the name of the container as its hostname. For example, to make a HTTP request to port 8080 on my-container from another container,
use http://my-container:8080.
This allows other containers to reference my-container by using other-name:
containers:
my-container:
# ...other config
additional_hostnames:
- other-nameReference: additional_hostnames
To configure processes inside my-container to resolve database.example.com to 1.2.3.4:
containers:
my-container:
# ...other config
additional_hosts:
database.example.com: 1.2.3.4Reference: additional_hosts
containers:
my-container:
# ...other config
run_as_current_user:
enabled: true
home_directory: /home/container-userReference: run_as_current_user