Utilizing Multi-Container Functionality with IBM Cloud Developer Tools CLI

By: Brian Clarke

Utilizing Multi-Container Functionality with IBM Cloud Developer Tools CLI

The latest update to the IBM Cloud Developer Tools CLI, version 1.1.0, provides support for applications that use multiple containers which are configured using Docker Compose yaml files. These files contain necessary information about the containers you wish to run. With Docker installed, you already have the requisite dependency to run multiple containers locally.

Why Multiple Containers?

If you’re wondering why you’d want to use an app that needs multiple containers locally, let’s first think about what makes up a cloud native application, and how you go about building cloud native applications. Let’s consider a basic microservice for reading and writing data from a database. You might have two parts of this service – one being the application (Node, Java, Swift, Python, etc…) and a database… perhaps even a caching server or some other components, but let’s keep it simple for now.

If you’re using a cloud-hosted database, like IBM Cloud’s MongoDB or Cloudant databases, then you might initially think that you only need one container: your application server, because you are hitting a database in the cloud. Now ask yourself, “Do I want to be able to work on my application while disconnected from the cloud?” or “Is there is a free tier for my production system’s cloud database?” Both wanting to be able to work offline with a local database, and wanting to use local OSS instances of the database are cases where you might want a project that uses multiple containers. With multiple containers, you can have your entire environment contained locally, which you can manage and coordinate using Docker Compose files.

Running with Multiple Containers

To run with multiple containers, you must provide the path to a Docker Compose file in the cli-config.yml for the dockerfile-run entry:

dockerfile-run : "docker-compose.yml"

or provide the path via command line as such:

bx dev run --dockerfile-run [/path/to/Compose/file]

The Compose file should be a valid .YML or .YAML file and specify your application’s services. By providing the Compose file, the Developer Tools CLI recognizes that you want to run with multiple containers. There are no additional options that you need to pass to specify running multiple containers. The run and stop commands use the dockerfile-run entry.

You may also wish to debug or test with multiple containers. If so, you would, similarly, provide the path to your Compose file in the cli-config.yml for the dockerfile-tools entry or via the command line. This file would be used for the builddebug and test commands.

Additionally, you may find it helpful to have several Compose files with various properties for running and testing different scenarios. In that case, you can provide multiple Compose files for both dockerfile-run and dockerfile-tools entries. In the cli-config.yml, the files should be separated by commas.

dockerfile-run : "docker-compose.yml, another-docker-compose.yml"

If you provide the paths via command line, you must surround a comma-delimited list of Compose files with double quotes.

bx dev run --dockerfile-run "[/path/to/compose/file, /path/to/another/compose/file, ...]"

Each successive Compose file that is provided will have higher priority in the case of duplicated entries. If you create your own Compose file, be sure to add the tty: true option to your service. This will ensure that the container remains running and does not exit upon running the bx dev run command.

Be the first to hear about news, product updates, and innovation from IBM Cloud