Skip to content

container

The container module manages containers using Docker or Podman. The runtime is auto-detected, or can be specified explicitly.

container "myapp" {
image "registry.example.com/myapp:latest"
state "running"
runtime "podman"
install-runtime #true
restart "always"
network "host"
command "nginx -g 'daemon off;'"
ports {
- "8080:80"
- "8443:443"
}
environment {
DATABASE_URL "postgres://db:5432/app"
LOG_LEVEL "info"
}
volumes {
- "/data/myapp:/app/data"
}
}
ParameterTypeDescription
(positional)stringContainer name
imagestringContainer image reference
statestring"running", "stopped", or "absent"
runtimestring"docker" or "podman" (default: auto-detect)
install-runtimebooleanAuto-install the runtime if not found
networkstringNetwork mode: "host", "bridge", "none", or a custom network name (auto-created if it doesn’t exist)
restartstringRestart policy: "always", "on-failure", "no"
commandstringCustom command to run in the container (overrides image default)
portslistPort mappings (host:container)
environmentmapEnvironment variables
volumeslistVolume mounts (host:container)

The module checks if a container with the given name exists and is in the desired state. For running, it compares a hash of all configuration parameters (image, network, restart policy, ports, environment, volumes, and command) against a label stored on the container. If any parameter changes, the container is recreated.

When network is set to a name other than host, bridge, none, or default, the module automatically creates the network if it doesn’t already exist. This lets containers on the same custom network communicate by container name.

container "redis" {
image "redis:7"
network "app-net"
}
container "webapp" {
image "myapp:latest"
network "app-net"
environment {
REDIS_URL "redis://redis:6379"
}
}

See the container-app example for a complete containerized deployment.