Menu

Installing and Using docker-compose

Docker, Machine, and iOS Builds > Installing and Using docker-compose

To use docker-compose with the docker key, install it in your primary container during the job execution with the Remote Docker Environment activated by adding the following to your config.yml file:

- run:
    name: Install Docker Compose
    command: |
      curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
      chmod +x ~/docker-compose
      sudo mv ~/docker-compose /usr/local/bin/docker-compose

Then, to activate the Remote Docker Environment, add the setup_remote_docker step:

- setup_remote_docker

This step enables you to add docker-compose commands to build images:

docker-compose build

Or to run the whole system:

docker-compose up -d

In the following example, the whole system starts, then verifies it is running and responding to requests:

      - run:
          name: Start container and verify it's working
          command: |
            set -x
            docker-compose up -d
            docker run --network container:contacts \
              appropriate/curl --retry 10 --retry-delay 1 --retry-connrefused http://localhost:8080/contacts/test

See the Example docker-compose Project on GitHub for a demonstration and use the full configuration file as a template for your own projects.

Note: The primary container runs in a separate environment from Remote Docker and the two cannot communicate directly. To interact with a running service, use docker and a container running in the service’s network.

Using Docker Compose with Machine Executor

If you want to use docker compose to manage a multi-container setup with a docker-compose file, use the machine key in your config.yml file and use docker-compose as you would normally. That is, if you have a docker-compose file that shares local directories with a container, this will work as expected. Refer to Docker’s documentation of Your first docker-compose.yml file for details. Note: There is an overhead for provisioning a machine executor as a result of spinning up a private Docker server. Use of the machine key may require additional fees in a future pricing update.

Using Docker Compose with Docker Executor

Using docker combined with setup_remote_docker provides a remote engine similar to the one created with docker-machine, but volume mounting and port forwarding do not work the same way in this setup. The remote docker daemon runs on a different system than the docker CLI and docker compose, so you must move data around to make this work. Mounting can usually be solved by making content available in a docker volume. It is possible to load data into a docker volume by using docker cp to get the data from the CLI host into a container running on the docker remote host.

This combination is required if you want to build docker images for deployment. See the Mounting Folders section of the Running Docker Commands for examples and details.