Install Terraform in Docker Containers
Run Terraform in Docker containers for consistent CI/CD environments. Official HashiCorp image, custom Dockerfiles, and Docker Compose workflows.
Terraform
Install Terraform on Alpine Linux for Docker containers and lightweight environments. Binary install, apk package, and minimal Docker images.
apk add --no-cache terraform --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
terraform versionapk add --no-cache curl unzip
TERRAFORM_VERSION="1.8.5"
curl -LO "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
mv terraform /usr/local/bin/
rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip"
terraform versionFor ARM (Raspberry Pi, Graviton):
curl -LO "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_arm64.zip"# Alpine 3.19+
apk add --no-cache terraform --repository=https://dl-cdn.alpinelinux.org/alpine/edge/communityFROM alpine:3.19
ARG TERRAFORM_VERSION=1.8.5
RUN apk add --no-cache curl unzip && \
curl -LO "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -d /usr/local/bin/ && \
rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \
apk del curl unzip && \
terraform version
WORKDIR /workspace
ENTRYPOINT ["terraform"]docker build -t terraform-alpine .
docker run --rm -v $(pwd):/workspace terraform-alpine version
# Image size: ~80MB (vs ~350MB for hashicorp/terraform)FROM alpine:3.19
ARG TERRAFORM_VERSION=1.8.5
RUN apk add --no-cache \
curl unzip bash jq git openssh-client \
python3 py3-pip && \
curl -LO "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \
unzip "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" -d /usr/local/bin/ && \
rm "terraform_${TERRAFORM_VERSION}_linux_amd64.zip" && \
pip3 install awscli --break-system-packages
WORKDIR /workspace
ENTRYPOINT ["/bin/bash"]| Feature | Alpine | Ubuntu | hashicorp/terraform |
|---|---|---|---|
| Base image | ~7 MB | ~78 MB | ~350 MB |
| With Terraform | ~80 MB | ~150 MB | ~350 MB |
| Package manager | apk | apt | apk |
| Shell | ash (busybox) | bash | ash |
| Best for | CI/CD, minimal containers | Dev environments | Quick start |
# "not found" error — Alpine uses musl, not glibc
# Terraform static binary works on both — this shouldn't happen
# If it does, install gcompat:
apk add --no-cache gcompatAlpine Linux produces the smallest Terraform Docker images (~80 MB). Use the binary download method for version pinning in CI/CD, or the community repository for quick installs. Alpine is ideal for CI/CD runner images where image pull time matters.
Run Terraform in Docker containers for consistent CI/CD environments. Official HashiCorp image, custom Dockerfiles, and Docker Compose workflows.
Install and run Terraform on Ubuntu 26.04 LTS Resolute Raccoon. Covers sudo-rs as default, APT 3.2 rollback, Kernel 7.0, Wayland-only, ROCm, and building...
TerraformDeploy and manage Docker containers with Terraform. Covers the Docker provider, images, containers, networks, and volumes with practical examples.
TerraformStep-by-step guide to install Terraform on AlmaLinux 10. Install HashiCorp Terraform using dnf, verify the installation, and configure your first project.