Run the Civo CLI in Docker with persistent config and Kubernetes support

Learn how to run the Civo CLI in Docker while persisting your API key and kubeconfig, set up aliases for seamless use, and manage instances and Kubernetes easily.

2 minutes reading time

Written by

Kunal Kushwaha
Kunal Kushwaha

Senior Developer Advocate EMEA @ Cast AI

Civo's CLI utility can be run inside a Docker container, allowing you to keep your host system clean while still managing your infrastructure.

Step 1: Prepare configuration files

Create the required configuration files and directories:

mkdir -p $HOME/.kube
touch $HOME/.civo.json
touch $HOME/.kube/config

The .civo.json file stores your API key, and the kubeconfig file enables Kubernetes access via kubectl.

Step 2: Run the Civo CLI in Docker

To persist your API key across runs, mount the config file into the container:

docker run -it --rm \
-v $HOME/.civo.json:/.civo.json \
civo/cli:latest

Step 3: Enable Kubernetes support (kubectl included)

The Civo CLI image includes kubectl. To use it, mount your kubeconfig file into the container:

docker run -it --rm \
-v $HOME/.civo.json:/.civo.json \
-v $HOME/.kube/config:/root/.kube/config \
civo/cli:latest

Without this mount, Kubernetes commands will not work because the container cannot access your cluster configuration.

Step 4: Set up a convenient alias

To simplify usage, you can create an alias so civo behaves like a locally installed CLI.

alias civo="docker run -it --rm \
-v $HOME/.civo.json:/.civo.json \
-v $HOME/.kube/config:/root/.kube/config \
civo/cli:latest"

Add this line to your shell config file:

  • ~/.bashrc or ~/.bash_profile
  • ~/.zshrc

Then reload your shell:

source ~/.bashrc

Step 5: Initialize your API key

On first run, you’ll need to add your API key:

civo apikey add

This will populate your mounted .civo.json file so credentials persist between runs.

Step 6: Example usage

Once the alias is set up, you can use the CLI normally:

civo sshkey list
civo instance list
civo instance create --size g4s.xsmall
civo k8s list

Summary

By running the Civo CLI in Docker with mounted config files, you get:

  • Persistent authentication
  • Built-in Kubernetes tooling via kubectl
  • A clean host environment with no local installation required
Kunal Kushwaha
Kunal Kushwaha

Senior Developer Advocate EMEA @ Cast AI

Kunal Kushwaha is a developer advocate, educator, and cloud-native specialist with extensive experience helping developers adopt modern infrastructure technologies. He currently works as Senior Developer Advocate at CAST AI, where he leads developer relations initiatives across the EMEA region.

Previously, Kunal spent more than four years at Civo in several leadership roles, including Field CTO and Developer Relations Manager. He is also the founder of WeMakeDevs, a global community initiative that mentors aspiring developers and promotes accessible technology education through online content and events.

View author profile