Docker
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: Docker CloudTruth CLI
Method 2: Docker Environment File
Prerequisites
Working knowledge of Docker.
You have created one or more CloudTruth Parameters.
You have created a CloudTruth API token.
Method 1: Docker CloudTruth CLI
The CloudTruth CLI can be installed as part of your docker Linux container.
This is an example CMD
that will print the environment variables from the container environment.
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.
Now you can build the image from your directory.
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.
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.
Method 2: Docker Environment File
You can also use CloudTruth Parameters inside a Docker container by using Docker run --env-file
and passing parameters with the cloudtruth parameter export docker
CloudTruth CLI command from your local environment.
You can create an environment file with the CloudTruth CLI.
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.
This can also be accomplished in a single line using Bash substitution and embedding the CloudTruth CLI command directly in Docker run.
Last updated