Using docker-compose

If you use docker-compose, you can use it in CircleCI 2.0 as well using the Remote Docker Environment. We’ve prepared an example project to demonstrate it.

You can use the full config file as a template for your own projects. Here, we’ll just cover the relevant parts.

In order to use docker-compose, you’ll need to have it in your primary container. You can either pre-install it in your custom image (recommended) or install it during the job’s execution:

- run:
    name: Install Docker Compose
    command: |
      set -x
      curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose
      chmod +x /usr/local/bin/docker-compose

To activate the Remote Docker Environment, you need use this special step:

- setup_remote_docker

After that, you can use docker-compose as usual. You can build images:

docker-compose build

Or run the whole system:

docker-compose up -d

In our example, we start the whole system, then verify that it’s 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

Note that, to interact with a running service, we don’t just curl it from the primary-container, but instead use docker and a container running in the service’s network. This is because your primary container and Remote Docker live in separate environments and can’t communicate directly.

If you have any questions, head over to our community forum for support from us and other users.