Skip to content
LoginGet Started

Docker

CloudTruth and Docker Compose

August 23, 2022

When thinking about configuration data, especially around what parameters and variables you're using in a Docker container, there can be a ton of moving parts. Whether it's ports, the container image being used, volumes that are used by the container, or even secrets that are being passed in for a MySQL environment.

In this blog post, you'll learn how and where you can store your Docker Compose configuration data using CloudTruth.

What Is Docker Compose

Docker Compose was built with multi-container applications (microservices) in mind. The idea was to have the ability to have an orchestration platform that can deploy and manage multiple containers that make up an application.

For example, let's say you have a container for:

  • A database
  • An API
  • A frontend

The database will most likely have a volume that it points to, along with the API if it's stateful.

If you have all of these container images that make up your application, you need a way to run them, ideally together. Docker Compose fills the gap of having to deploy all of the containers separately and allows you to define the spec data inside of the containers.

Two of the advantages to Docker Compose is that you can define your app in a single stack file and others can contribute to it. For example, thinking about the database, API, and frontend container app from earlier, you can define all three of the specs for each container inside of a single stack file. Then, you can push that stack file to source control so others on your team can modify, contribute, and use it.

When you're thinking about Docker Compose and another system like Kubernetes, they're both doing the same thing - orchestrating containers. The key difference between, for example, Docker Compose and Kubernetes is Docker Compose deploys containers and orchestrates them on one server, whereas Kubernetes scales the containers to multiple servers (worker nodes). Using Docker Compose, you can still have multiple replicas of your containerized app. They'll just be hosted on one server.

Setting Up CloudTruth For Docker Compose

Now that you know what Docker Compose is, let's learn how to get a CloudTruth environment up and running to pass in the configuration data to Docker Compose to deploy containerized apps.

First, log into your CloudTruth portal and click on Projects.

CloudTruth Docker Compose Getting Started 1

Next, click on the blue Add Project button.

CloudTruth Docker Compose Getting Started 2

Create a new project and call it "compose".

CloudTruth Docker Compose Getting Started 3

Now that the project is created, you can open up a terminal and add in your parameters. For the purposes of this blog post and the Docker Compose file you'll use in the next section, you can create the following parameters via the CloudTruth CLI.

cloudtruth --project compose parameter set --value 8080 destinationPort
cloudtruth --project compose parameter set --value 80 sourcePort

If you log into the CloudTruth portal and look under the compose project, you'll now see the newly created parameters.

CloudTruth Docker Compose Getting Started 4

In the next section, let's learn how to set up the Docker Compose file to inject the environment variable from CloudTruth.

Deploying a Docker Compose Configuration

The CloudTruth environment, including the proper project and parameters are configured. Now, it's time to create a Docker Compose stack and set up the environment variables so they can be ingested from CloudTruth.

First, open up a code editor of your choosing. For example, VS Code.

Next, create a new file, call it docker-compose.yml, and add in the following Docker Compose stack.

The stack specifies a containerized app, but the containerized apps configuration data, like it's ports, are going to come from CloudTruth.

version: "3.9"
services:
web:
image: nginx:latest
environment:
- destinationPort
- sourcePort
- dockerImage

Next, run the following command for the CloudTruth CLI to retrieve the values for the ports from CloudTruth, which will pass your CloudTruth parameters to Docker Compose and display the variables selected.

cloudtruth --project "compose" --env development run -- docker compose up

Run the following command to list the Docker Compose stacks.

docker compose ls

You can now see the Docker Compose stack running.

You'll see an output similar to the screenshot below.

CloudTruth Docker Compose Getting Started 5

Congrats! You have successfully combined CloudTuth and Docker Compose for your automated deployments.

 

 

Join ‘The Pipeline’

Our bite-sized newsletter with DevSecOps industry tips and security alerts to increase pipeline velocity and system security.

Subscribe For Free

Continue exploring

Browse All Talks

Continue Reading