CloudTruth Documentation
Sign InAPIIntegrationsGitHubVisit our website
  • Overview
  • Getting Started
  • Architecture
    • 🔒Security Overview
  • Copilot
  • 🏢Org management
    • Account Setup
    • Access Control
      • 🔑API Tokens
      • 🌐Protecting Projects and Environments
      • 👥Users
    • Audit Log
  • 🛠️Config Management
    • Projects
    • Parameters
      • Sharing Config Data
      • Parameter Management
        • Internal Values
          • Dynamic Values
        • External Values
          • Terraform Remote State Files
        • Parameter Override
        • Environment Value Override
      • Parameter and Parameter Value Inheritance
      • Value Comparison
      • Value History
      • Value Validation
      • Value Expiration
    • Environments and Tags
    • Templates
      • 📒Sample Templates
    • Actions
      • Import Actions
      • Push Actions
    • CLI & API
      • CloudTruth CLI
      • Rest API
    • Integrations
      • Argo CD
      • Atlassian Compass
      • AWS
        • AWS Connection
        • AWS Role
          • CloudFormation
          • Terrraform
          • AWS Console
        • Parameter Store (SSM)
        • S3
        • Secrets Manager
      • Azure Key Vault
      • Bitbucket Pipelines
      • Docker
      • Docker Compose
      • GitHub
      • GitHub Actions
      • GitLab
      • Harness
      • Jenkins
      • Kubernetes
      • Pulumi
      • Terraform
      • Terragrunt
      • Explorer
      • Circle CI
    • Events, Notifications, Webhooks
    • Types
  • 🔎REPORTING
    • Compare
    • History
    • Expirations
  • 🚀PRODUCT
    • What is CloudTruth?
    • Interactive Demo
    • Kubernetes
    • Terraform
    • CI/CD Pipeline Configuration
    • Cloud CMDB
    • Secrets Management
    • GitOps
    • Our Manifesto
    • Open Source
    • FAQs
    • Our Mission
  • 📚Reference
    • 🎓Quick Start Videos
      • What is CloudTruth?
      • CloudTruth in Action
      • Environments and Projects
      • Secrets, Parameters, ENV variables
      • Audit Logs, RBAC, SSO
      • Containers - Kubernetes, Docker
      • Infrastructure as Code (IaC) - Terraform, Cloudformation, CDK, Azure Bicep, Pulumi
      • CICD Pipelines - GitHub Actions, ArgoCD, Jenkins, CircleCI, Harness, GitLab Pipelines
      • AWS Videos - Secret Manager, Parameter Store, S3, IAM
      • Azure Videos - Azure DevOps, Azure Bicep, PowerShell
    • Knowledge Base
      • Best Practices
        • Versioned Releases
      • CLI
        • History comparison of deleted parameters with null values
      • Integrations
        • Advanced AWS IAM policy permissions
        • K8s pull image from private Docker registry
        • S3 Region Selection
      • Templates
        • Templates render quotations in key values as quot
    • Roadmap and New Features
    • JMESPath Reference
    • REST API
Powered by GitBook

Copyright© 2023 CloudTruth

On this page
  • Prerequisites
  • Method 1: Docker CloudTruth CLI
  • Method 2: Docker Environment File

Was this helpful?

  1. Config Management
  2. Integrations

Docker

PreviousBitbucket PipelinesNextDocker Compose

Last updated 3 years ago

Was this helpful?

This walkthrough will show you two methods of using CloudTruth to pass environment variables to a Docker container. The first method installs the CloudTruth CLI directly in your docker image, the second method uses a CloudTruth environment file with docker run.

  • Method 1:

  • Method 2:

Prerequisites

  • Working knowledge of Docker.

  • You have created one or more .

  • You have created a .

Method 1: Docker CloudTruth CLI

The CloudTruth CLI can be installed as part of your docker Linux container.

# Install the CloudTruth CLI
RUN (curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh || wget -qO- https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh) | sh

This is an example CMD that will print the environment variables from the container environment.

CMD ["cloudtruth", "--project", "MyFirstProject", "run", "--", "printenv"]

To try this out, create a new directory called tutorial. Inside the directory make a new Dockerfile with the following contents. Depending on your container image you may need to install curl or wget.

FROM alpine

# Install the CloudTruth CLI
RUN (curl -sL https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh || wget -qO- https://github.com/cloudtruth/cloudtruth-cli/releases/latest/download/install.sh) | sh

CMD ["cloudtruth", "--project", "MyFirstProject", "run", "--", "printenv"]

Now you can build the image from your directory.

docker build -t tutorial .

Run your tutorial Docker image and pass in the CloudTruth API key to allow CloudTruth to authenticate in the container instance. This will print your CloudTruth Parameters and container environment variables.

docker run -it --rm -e CLOUDTRUTH_API_KEY="YOUR_API_KEY" tutorial

You can also export the CloudTruth API key to your local environment and then pass the key into the container without specifying the key value.

export CLOUDTRUTH_API_KEY="YOUR_API_KEY"
docker run -it --rm -e CLOUDTRUTH_API_KEY tutorial

Method 2: Docker Environment File

You can create an environment file with the CloudTruth CLI.

 cloudtruth --project MyFirstProject parameter export docker > dotenv

The dotenv file can now be passed to Docker with the --env-file flag. This will pull down an alpine container, issue the printenv command and display your CloudTruth parameters and container environment variables.

 docker run -it --rm --env-file dotenv alpine printenv

This can also be accomplished in a single line using Bash substitution and embedding the CloudTruth CLI command directly in Docker run.

docker run -it --rm --env-file <(cloudtruth --project MyFirstProject parameter export docker) alpine printenv

You can also use CloudTruth Parameters inside a Docker container by using and passing parameters with the cloudtruth parameter export docker CloudTruth CLI command from your local environment.

🛠️
Docker run --env-file
CloudTruth Parameters
Docker CloudTruth CLI
Docker Environment File
CloudTruth API token