dokploy_compose (Resource)
A Dokploy compose service: a docker-compose project or a Docker Swarm stack.
Set exactly one of the github, git, or raw source blocks.
~> Dokploy also supports GitLab, Bitbucket, and Gitea sources. The provider does not model them, for the same reason that the dokploy_github_provider data source covers only GitHub: no test server was available to observe their shapes. The provider does not infer request shapes.
~> dokploy_compose owns the whole service. An apply of this resource rewrites the source and the operational configuration of the service. The next apply therefore replaces each setting that changed in the Dokploy UI.
Example Usage
resource "dokploy_project" "example" {
name = "example"
}
# Inline compose file. Dokploy fetches nothing: the YAML below is the source.
resource "dokploy_compose" "inline" {
name = "inline-stack"
environment_id = dokploy_project.example.production_environment_id
description = "Defined entirely in Terraform"
# Recreate the volumes on each deploy that Terraform starts. The data in
# the volumes is lost, so keep the default of false for a stateful stack.
fresh_volumes = false
raw = {
compose_file = <<-YAML
services:
web:
image: nginx:alpine
ports:
- "8080:80"
YAML
}
}
# From a GitHub App repository. github_id comes from the data source, not
# from a hardcoded opaque id.
data "dokploy_github_provider" "main" {
name = "my-org"
}
resource "dokploy_compose" "from_github" {
name = "github-stack"
environment_id = dokploy_project.example.production_environment_id
github = {
repository = "my-stack"
owner = "my-org"
branch = "main"
github_id = data.dokploy_github_provider.main.id
}
compose_path = "./deploy/docker-compose.yml"
auto_deploy = true
trigger_type = "push"
watch_paths = ["deploy/**"]
}
# From a plain git remote, run as a Docker Swarm stack.
resource "dokploy_compose" "from_git" {
name = "git-stack"
environment_id = dokploy_project.example.production_environment_id
compose_type = "stack"
git = {
url = "https://github.com/my-org/my-stack.git"
branch = "main"
}
env = <<-ENV
LOG_LEVEL=info
REGION=eu-west-1
ENV
}
# Route traffic to one service inside the stack.
resource "dokploy_domain" "web" {
host = "example.com"
compose_id = dokploy_compose.inline.id
service_name = "web"
port = 80
https = true
}
# From a GitLab project, a Bitbucket repository, or a Gitea repository. Each
# block names the provider record that holds the credentials.
resource "dokploy_compose" "from_gitlab" {
name = "gitlab-stack"
environment_id = dokploy_project.example.production_environment_id
gitlab = {
gitlab_id = dokploy_gitlab_provider.main.id
owner = "my-group"
repository = "my-stack"
branch = "main"
project_id = 12345678
path_namespace = "my-group/my-stack"
}
}
resource "dokploy_compose" "from_gitea" {
name = "gitea-stack"
environment_id = dokploy_project.example.production_environment_id
gitea = {
gitea_id = dokploy_gitea_provider.main.id
owner = "acme"
repository = "my-stack"
branch = "main"
}
compose_path = "./compose/production.yml"
}Schema
Required
environment_id(String) Id of the environment that holds this service. Usedokploy_project.production_environment_idfor the default environment.name(String) Display name of the compose service.
Optional
app_name(String) Internal Dokploy app name,<app_name_prefix>-<suffix>. The server generates it at create. You cannot set it; setapp_name_prefixinstead.app_name_prefix(String) Prefix of the Dokploy app name. Dokploy appends-<suffix>(six random lowercase characters) at create and never changes the app name afterwards. Defaults toname. Use lowercase letters, digits, dots, underscores, and hyphens; 56 characters at most. A change replaces the resource. After an import the provider derives the value fromapp_name.auto_deploy(Boolean) Redeploy automatically when the source repository changes. The server setstrueon a new service. An explicit null is a valid stored state.bitbucket(Attributes) Source the compose file from a Bitbucket repository, through adokploy_bitbucket_provider. (see nested schema for bitbucket)command(String) Replaces the command that Dokploy runs to deploy this stack, normallydocker compose up. It is a substitute, not an addition. If the command does not deploy the stack itself, each deploy fails. Leave it unset unless you must replace the deploy command.compose_path(String) Path to the compose file inside the repository. Defaults to./docker-compose.yml. An empty string is not valid. Therawsource ignores it.compose_type(String) How Dokploy runs the service: as adocker-composeproject or as a Docker Swarmstack. Defaults todocker-compose.create_env_file(Boolean) Write the environment variables to a.envfile for the compose project. Defaults totrue, the Dokploy default for a new service.deploy_on_change(Boolean) Deploy after a create, and after a change to an attribute that starts a deploy. Defaults totrue.deployment_timeout(String) The maximum wait for a deploy to reach a terminal status, as a Go duration string. Defaults to"15m". On timeout, the apply fails, but the deploy continues on the server.description(String) Free-form description.enable_submodules(Boolean) Clone git submodules with the repository. Defaults tofalse.env(String) Extra environment variables in the native Dokploy multilineKEY=valueformat. Use Terraform sensitive variables for secret values. An omitted value and""both read back as null. Omit the attribute to clear it.fresh_volumes(Boolean) Recreate the volumes of the stack on each deploy that this provider starts (Dokploy v0.30.5 and later). Defaults tofalse. The data in the volumes is lost on such a deploy. A change of this attribute alone starts no deploy.git(Attributes) Source the compose file from a plain git remote. (see nested schema for git)gitea(Attributes) Source the compose file from a Gitea repository, through adokploy_gitea_provider. The provider must be authorized in the Dokploy UI before a deploy can clone from it. (see nested schema for gitea)github(Attributes) Source the compose file from a GitHub App repository. (see nested schema for github)gitlab(Attributes) Source the compose file from a GitLab project, through adokploy_gitlab_provider. The provider must be authorized in the Dokploy UI before a deploy can clone from it. (see nested schema for gitlab)icon(String) Service icon for the Dokploy UI: an icon name or a data URI, up to 2 MB.randomize(Boolean) Randomize the generated resource names withsuffix. Defaults tofalse.raw(Attributes) Supply the compose file inline, without a repository. (see nested schema for raw)server_id(String) Id of the remote server that runs the service. Defaults to the Dokploy host.service_networks(Attributes Set) Docker network attachments per compose service, available since Dokploy v0.30.0. Each entry names one compose service and the Dokploy network ids to attach. The attachments apply on the next deploy. (see nested schema for service_networks)suffix(String) Suffix for the generated resource names whenrandomizeistrue.trigger_type(String) Which git event triggers an auto-deploy:pushortag.watch_paths(List of String) Auto-deploy only when a change touches one of these paths.
Read-Only
created_at(String) Creation timestamp from the server.id(String) Compose service id.status(String) Service status from Dokploy.
Nested Schema for bitbucket
Required:
bitbucket_id(String) Id of the Bitbucket provider in Dokploy:dokploy_bitbucket_provider.idor the data source’sid.branch(String) Branch to deploy.owner(String) Workspace or user that owns the repository.repository(String) Repository name.repository_slug(String) Repository slug, the last part of the repository URL. It usually equals the repository name in lowercase.
Nested Schema for git
Required:
branch(String) Branch to deploy.url(String) Git remote URL.
Optional:
ssh_key_id(String) Id of a Dokploy SSH key, for private repositories.
Nested Schema for gitea
Required:
branch(String) Branch to deploy.gitea_id(String) Id of the Gitea provider in Dokploy:dokploy_gitea_provider.idor the data source’sid.owner(String) Owner of the repository: a user or an organization.repository(String) Repository name.
Nested Schema for github
Required:
branch(String) Branch to deploy.github_id(String) Id of the Dokploy GitHub App. See thedokploy_github_providerdata source.owner(String) Repository owner.repository(String) Repository name.
Nested Schema for gitlab
Required:
branch(String) Branch to deploy.gitlab_id(String) Id of the GitLab provider in Dokploy:dokploy_gitlab_provider.idor the data source’sid.owner(String) Owner of the project: a user or a group.path_namespace(String) Full path of the project, for examplemy-group/my-project. GitLab addresses a project by it.project_id(Number) Numeric GitLab project id, shown on the project’s settings page.repository(String) Project name.
Nested Schema for raw
Required:
compose_file(String) The compose YAML, verbatim.
Nested Schema for service_networks
Required:
network_ids(Set of String) Dokploy network ids to attach to this service.service_name(String) Compose service name, as written in the compose file.
Optional:
detach_dokploy_network(Boolean) Detach the shareddokploy-networkfrom this service. Defaults tofalse.
Import
Import is supported using the following syntax:
In Terraform v1.5.0 and later, the import block can be used with the id attribute, for example:
import {
to = dokploy_compose.inline
id = "V1StGXR8_Z5jdHi6B-myT"
}The terraform import command can be used, for example:
terraform import dokploy_compose.inline V1StGXR8_Z5jdHi6B-myT