Skip to content

Instantly share code, notes, and snippets.

@carmark
Last active May 25, 2016 07:00
Show Gist options
  • Save carmark/ff98a4701c58181931aa497be40fa5b4 to your computer and use it in GitHub Desktop.
Save carmark/ff98a4701c58181931aa497be40fa5b4 to your computer and use it in GitHub Desktop.

Command

compose help

hyper --host=tcp://147.75.195.39:6443 compose --help

Usage:	hyper compose [OPTIONS] <COMMAND>

Commands:
  create                   Creates containers for a service
  down                     Stop and remove containers, images, and volumes
  kill                     Force stop service containers
  ps                       List containers
  rm                       Remove stopped service containers
  run                      Run a one-off command
  scale                    Set number of containers for a service
  start                    Start services
  stop                     Stop services
  up                       Create and start containers

Run 'hyper compose COMMAND --help' for more information on a command.

  --help             Print usage

compose stop

hyper --host=tcp://147.75.195.39:6443 compose stop --help

Usage:	hyper compose stop [OPTIONS] [SERVICE...]

Stop running containers without removing them.

They can be started again with `hyper compose start`.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name
  -t, --timeout=10                    Specify a shutdown timeout in seconds.

compose up

hyper --host=tcp://147.75.195.39:6443 compose up --help

Usage:	hyper compose up [OPTIONS] [SERVICE...]

Builds, (re)creates, starts, and attaches to containers for a service.

Unless they are already running, this command also starts any linked services.

The `hyper compose up` command aggregates the output of each container. When
the command exits, all containers are stopped. Running `hyper compose up -d`
starts the containers in the background and leaves them running.

If there are existing containers for a service, and the service's configuration
or image was changed after the container's creation, `hyper compose up` picks
up the changes by stopping and recreating the containers (preserving mounted
volumes). To prevent Compose from picking up changes, use the `--no-recreate`
flag.

If you want to force Compose to stop and recreate all containers, use the
`--force-recreate` flag.

   -d                                  Detached mode: Run containers in the background,
                                      print new container names.
                                      Incompatible with --abort-on-container-exit.
  -f, --file=docker-compose.yml       Specify an alternate compose file
  --force-recreate                    Recreate containers even if their configuration
                                      and image haven't changed.
                                      Incompatible with --no-recreate.
  --help                              Print usage
  --no-recreate                       If containers already exist, don't recreate them.
                                      Incompatible with --force-recreate.
  -p, --project-name=hyper-compose    Specify an alternate project name

compose ps

hyper --host=tcp://147.75.195.39:6443 compose ps --help

Usage:	hyper compose ps [OPTIONS] [SERVICE...]

List containers.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name
  -q, --quiet                         Only display IDs

compose kill

hyper --host=tcp://147.75.195.39:6443 compose kill --help

Usage:	hyper compose kill [OPTIONS] [SERVICE...]

Force stop service containers.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name

compose create

hyper --host=tcp://147.75.195.39:6443 compose create --help

Usage:	hyper compose create [OPTIONS] [SERVICE...]

Creates containers for a service.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --force-recreate                    Recreate containers even if their configuration
                                      and image haven't changed.
                                      Incompatible with --no-recreate.
  --help                              Print usage
  --no-recreate                       If containers already exist, don't recreate them.
                                      Incompatible with --force-recreate.
  -p, --project-name=hyper-compose    Specify an alternate project name

compose down

hyper --host=tcp://147.75.195.39:6443 compose down --help

Usage:	hyper compose down [OPTIONS]

Stop and remove containers, images, and volumes
created by `up`. Only containers and networks are removed by default.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name
  --remove-orphans                    Remove containers for services not defined in the Compose file
  --rmi                               Remove images, type may be one of: 'all' to remove
                                      all images, or 'local' to remove only images that
                                      don't have an custom name set by the `image` field
  -v, --volumes                       Remove data volumes

compose start

hyper --host=tcp://147.75.195.39:6443 compose start --help

Usage:	hyper compose start [OPTIONS] [SERVICE...]

Start existing containers.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name

compose rm

hyper --host=tcp://147.75.195.39:6443 compose rm --help

Usage:	hyper compose rm [OPTIONS] [SERVICE...]

Remove stopped service containers.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name
  -v                                  Remove volumes associated with containers

compose scale

hyper --host=tcp://147.75.195.39:6443 compose scale --help

Usage:	hyper compose scale [OPTIONS] [SERVICE=NUM...]

Set number of containers to run for a service.

  -f, --file=docker-compose.yml       Specify an alternate compose file
  --help                              Print usage
  -p, --project-name=hyper-compose    Specify an alternate project name
  -t, --timeout=10                    Specify a shutdown timeout in seconds

Compose file reference

command

Override the default command.

command: bundle exec thin -p 3000

The command can also be a list:

command: [bundle, exec, thin, -p, 3000]

container_name

Specify a custom container name, rather than a generated default name.

container_name: my-web-container

Because Hyper_ container names must be unique, you cannot scale a service beyond 1 container if you have specified a custom name. Attempting to do so results in an error.

depends_on

Express dependency between services, which has two effects:

  • compose up will start services in dependency order. In the following example, db and redis will be started before web.

  • compose up SERVICE will automatically include SERVICE’s dependencies. In the following example, docker-compose up web will also create and start db and redis.

Simple example:

version: '2'
services:
  web:
    build: .
    depends_on:
      - db
      - redis
  redis:
    image: redis
  db:
    image: postgres

Note: depends_on will not wait for db and redis to be “ready” before starting web - only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.

entrypoint

Override the default entrypoint.

entrypoint: /code/entrypoint.sh

The entrypoint can also be a list:

entrypoint:
    - php
    - -d
    - zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so
    - -d
    - memory_limit=-1
    - vendor/bin/phpunit

env_file

Add environment variables from a file. Can be a single value or a list.

If you have specified a Compose file with compose -f FILE, paths in env_file are relative to the directory that file is in.

Environment variables specified in environment override these values.

env_file: .env

env_file:
  - ./common.env
  - ./apps/web.env
  - /opt/secrets.env

Compose expects each line in an env file to be in VAR=VAL format. Lines beginning with # (i.e. comments) are ignored, as are blank lines.

# Set Rails/Rack environment
RACK_ENV=development

environment

Add environment variables. You can use either an array or a dictionary. Any boolean values; true, false, yes no, need to be enclosed in quotes to ensure they are not converted to True or False by the YML parser.

Environment variables with only a key are resolved to their values on the machine Compose is running on, which can be helpful for secret or host-specific values.

environment:
  RACK_ENV: development
  SHOW: 'true'
  SESSION_SECRET:

environment:
  - RACK_ENV=development
  - SHOW=true
  - SESSION_SECRET

extends

Extend another service, in the current file or another, optionally overriding configuration.

You can use extends on any service together with other configuration keys. The extends value must be a dictionary defined with a required service and an optional file key.

extends:
  file: common.yml
  service: webapp

The service the name of the service being extended, for example web or database. The file is the location of a Compose configuration file defining that service.

If you omit the file Compose looks for the service configuration in the current file. The file value can be an absolute or relative path. If you specify a relative path, Compose treats it as relative to the location of the current file.

You can extend a service that itself extends another. You can extend indefinitely. Compose does not support circular references and compose returns an error if it encounters one.

external_links

Link to containers started outside this docker-compose.yml or even outside of Compose, especially for containers that provide shared or common services. external_links follow semantics similar to links when specifying both the container name and the link alias (CONTAINER:ALIAS).

external_links:
 - redis_1
 - project_db_1:mysql
 - project_db_1:postgresql

Note: If you’re using the version 2 file format, the externally-created containers must be connected to at least one of the same networks as the service which is linking to them.

image

Specify the image to start the container from. Can either be a repository/tag or a partial image ID.

image: redis
image: ubuntu:14.04
image: tutum/influxdb
image: example-registry.com:4000/postgresql
image: a4bc65fd

If the image does not exist, Compose attempts to pull it, unless you have also specified build, in which case it builds it using the specified options and tags it with the specified tag.

labels

Add metadata to containers using Docker labels. You can use either an array or a dictionary.

It’s recommended that you use reverse-DNS notation to prevent your labels from conflicting with those used by other software.

labels:
  com.example.description: "Accounting webapp"
  com.example.department: "Finance"
  com.example.label-with-empty-value: ""

labels:
  - "com.example.description=Accounting webapp"
  - "com.example.department=Finance"
  - "com.example.label-with-empty-value"

links

Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.

web:
  links:
   - db
   - db:database
   - redis

Containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.

Links also express dependency between services in the same way as depends_on, so they determine the order of service startup.

volumes

Mount paths or named volumes, optionally specifying a path on the host machine (VOLUME:CONTAINER). For version 2 files, named volumes need to be specified with the top-level volumes key. When using version 1, the Docker Engine will create the named volume automatically if it doesn’t exist.

volumes:
  # Just specify a path and let the Engine create a volume
  - /var/lib/mysql

  # Named volume
  - datavolume:/var/lib/mysql

hostname

hostname: foo

domainname

domainname: foo.com

restart

restart: always

stdin_open

stdin_open: true

tty

tty: true

working_dir

working_dir: /code

Volume configuration reference

While it is possible to declare volumes on the fly as part of the service declaration, this section allows you to create named volumes that can be reused across multiple services, and are easily retrieved and inspected using the hyper command line or API.

external

If set to true, specifies that this volume has been created outside of Compose. docker-compose up will not attempt to create it, and will raise an error if it doesn’t exist.

In the example below, instead of attemping to create a volume called [projectname]_data, Compose will look for an existing volume simply called data and mount it into the db service’s containers.

version: '2'

services:
  db:
    image: postgres
    volumes:
      - data:/var/lib/postgres/data

volumes:
  data:
    external: true

You can also specify the name of the volume separately from the name used to refer to it within the Compose file:

volumes
  data:
    external:
      name: actual-name-of-volume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment