Skip to content

CLI reference

Note

This page reflects the options available in the most recent version of batect.

If you are not running the most recent version, run ./batect --help to see what options are available in your version.

Run a task

Run a task by running ./batect <task-name>. For example, to run the-task, run ./batect the-task.

You can also pass arguments to the task command by passing those arguments by running ./batect <task-name> -- <args...>. For example, to run the task the-task with the arguments arg1 arg2, run ./batect the-task -- arg1 arg2.

Set config variables from a file (--config-vars-file)

By default, batect will automatically apply values for config variables from the YAML file batect.local.yml if it exists.

Use --config-vars-file to specify a different file to use.

Values provided with --config-var take precedence over values provided in any file.

Example:

./batect --config-vars-file batect.ci.yml the-task

Example batect.ci.yml contents:

log_level: debug
user_name: alex

Set a config variable (--config-var)

Use --config-vars to specify values for an individual config variable.

Values must be in the format <variable name>=<variable value>.

Values provided with --config-var take precedence over values provided in a file (either explicitly with --config-vars-file or from the default batect.local.yml file) and default values defined in the configuration file.

Example:

./batect --config-var log_level=debug the-task

Override the image used by a container (--override-image)

By default, batect will use the image defined in the configuration file (either with image or build_directory).

Use this option to override the value in the configuration file and use a different image for a specific container.

Values must be in the format <container name>=<image>.

Example:

./batect --override-image build-env=ruby:2.7.0 the-task

Disable cleaning up (--no-cleanup, --no-cleanup-after-failure and --no-cleanup-after-success)

By default, batect will automatically cleanup all containers and other resources it creates while running a task. However, sometimes it can be useful to leave all the created containers running to diagnose issues running a task.

  • Use --no-cleanup-after-failure to not clean up if any task fails to start for any reason.
  • Use --no-cleanup-after-success to not clean up the containers and other resources created for the main task (the one specified on the command line) if it succeeds.
  • Use --no-cleanup to enable both of the above.

Example:

./batect --no-cleanup-after-failure the-task

By default, batect will automatically propagate proxy-related environment variables as described here. Use this option to disable this behaviour.

Example:

./batect --no-proxy-vars the-task

See a list of available tasks (--list-tasks or -T)

batect can produce a short summary of all tasks in the current configuration file along with their description, and grouped by their group.

For example, ./batect --list-tasks produces output like this:

Build tasks:
- build: Build the application.

Test tasks:
- continuousUnitTest: Run the unit tests in watch mode.
- unitTest: Run the unit tests once.

Utility tasks:
- outdated: Check for outdated dependencies.
- shell: Start a shell in the development environment.

Cleanup all caches for this project (--clean)

Running ./batect --clean will remove all caches created for this project.

This command respects the value of the --cache-type option and the BATECT_CACHE_TYPE environment variable.

Upgrade batect (--upgrade)

Running ./batect --upgrade will automatically upgrade batect in the current project to the latest available version.

Get help for batect's CLI (--help)

Running ./batect --help will show a summary of the options available on the command line.

Get batect, Docker and OS version information (--version)

Running ./batect --version will show a summary of the versions of batect, Docker and your operating system, which can be useful when diagnosing issues with batect.

Common options

Use a non-standard configuration file name (--config-file or -f)

By default, batect will use a configuration file called batect.yml in the current directory. Use this option to instruct batect to use a different file.

Example:

./batect --config-file my-other-config-file.yml the-task

Customise cache storage mechanism (--cache-type)

By default, batect will use a Docker volume for each cache mount. Use this option to instruct batect to use a different storage mechanism.

Supported values are:

  • volume: use Docker volumes
  • directory: use directories mounted from the project's .batect/caches directory

The BATECT_CACHE_TYPE environment variable can also be used to set the default cache type. If both the environment variable and the --cache-type option are set, the value given with --cache-type takes precedence.

Example:

./batect --cache-type=directory the-task

Set cache initialisation image (--linux-cache-init-image)

batect uses an image to initialise cache volumes before they are mounted. Use this option to override the default image. This is useful if you have cached the initialisation image on a local registry.

The BATECT_LINUX_CACHE_INIT_IMAGE environment variable can also be used to set the default initialisation image. If both the environment variable and the --linux-cache-init-image option are set, the value given with --linux-cache-init-image takes precedence.

Example:

./batect --linux-cache-init-image=my.registry.com/batect-cache-init-image:abcd1234 the-task

Customise Docker connection options

Use a non-standard Docker host (--docker-host)

By default, batect will connect to the Docker daemon using the path provided in the DOCKER_HOST environment variable, or the default path for your operating system if DOCKER_HOST is not set. Use this option to instruct batect to use a different path.

Example:

./batect --docker-host unix:///var/run/other-docker.sock the-task

Connect to Docker over TLS (--docker-tls and --docker-tls-verify)

By default, the Docker daemon only accepts plaintext connections from the local machine. If your daemon requires TLS, use the --docker-tls-verify option to instruct batect to use TLS. batect will also automatically enable this option if the DOCKER_TLS_VERIFY environment variable is set to 1.

If your daemon presents a certificate that does not match its hostname, use the --docker-tls option (without --docker-tls-verify) to instruct batect to not verify the hostname.

Warning

Using --docker-tls without --docker-tls-verify is insecure and should only be used if you understand the implications of this.

These options mirror the behaviour of the docker CLI's --tls and --tlsverify options.

Customise certificates used to provide authentication to daemon and to verify daemon's identity (--docker-cert-path, --docker-tls-ca-cert, --docker-tls-cert and --docker-tls-key)

If your Docker daemon requires TLS, batect needs three files in order to connect to it:

  • the CA certificate that can be used to verify certificates presented by the Docker daemon (--docker-tls-ca-cert)
  • the certificate that can be used to prove your identity to the Docker daemon (--docker-tls-cert) and corresponding private key (--docker-tls-key)

By default, these files are stored in ~/.docker and are named ca.pem, cert.pem and key.pem respectively.

You can instruct batect use a non-default location for any of these files with the options mentioned above, or override the default directory for these files with --docker-cert-path. If the DOCKER_CERT_PATH environment variable is set, batect will use that as the default directory.

If both --docker-cert-path (or DOCKER_CERT_PATH) and a path for an individual file is provided, the path for the individual file takes precedence.

These options mirror the behaviour of the docker CLI's --tlscacert, --tlscert and --tlskey options.

Create a debugging log (--log-file)

Use this option to instruct batect to generate a debugging log at the specified path as it runs. This may be requested if you submit an issue.

If the log file already exists, batect will append further log messages to the end of the file.

Example:

./batect --log-file /tmp/debugging-log.json the-task

Disable coloured output (--no-color)

By default, batect will produce coloured output if it detects that your console supports it. However, sometimes batect may incorrectly believe your console supports coloured output, or your console may incorrectly report that it supports coloured output when it does not. (This is a common issue with some CI systems.) This can lead to garbled or difficult to read output.

Passing this flag will disable all coloured output, even if batect believes your console supports it.

Example:

./batect --no-color the-task

Disable update notification (--no-update-notification)

batect automatically checks for updates at most once every 24 hours and displays a notification if a newer version is available.

Passing this flag will disable both the update check and notification.

Disable wrapper cache cleanup (--no-wrapper-cache-cleanup)

batect automatically removes old versions of itself that have been downloaded and cached locally if they haven't been used in 30 days.

Passing this flag will disable this cleanup process. You can manually remove these files from ~/.batect/cache yourself at any time.

Force a particular output style (--output or -o)

batect offers four styles of output:

  • fancy is best for interactive use, providing very clean output about the current state of execution and showing output from only the task container

  • simple is best for non-interactive use (eg. on CI), providing a log of what happened and showing output from only the task container

  • all displays output from all containers

  • quiet displays only the output from the task and error messages from batect

By default, batect will automatically pick an output style that it believes is appropriate for the environment it is running in - fancy if it believes your environment supports it, or simple otherwise.

A TTY (and stdin) are attached to the task container when using fancy, simple and quiet output styles. All other containers (and all containers when using all) will not have stdin or a TTY attached.

Passing this flag allows you to override what batect believes is appropriate.

Example:

./batect --output simple the-task

General notes

  • All command line options that take a value can be provided in --option=value or --option value format.