Skip to content

[Bug]: Docker cleanup coolify.managed label check never works due to Go template escaping error in CleanupDocker.php #8822

@recobalee88

Description

@recobalee88

Error Message and Logs

Description

The coolify.managed=true label check in CleanupDocker.phpbuildImagePruneCommand() is broken. The generated docker inspect --format command contains {{{{ (4 curly braces) instead of {{ (2), causing a Go template parsing error. As a result, all images without a running container reference are deleted regardless of their labels.

Affected Code

File: app/Actions/Server/CleanupDocker.php, method buildImagePruneCommand()

$commands[] = "docker images --format '{{.Repository}}:{{.Tag}}' | ".
    $grepCommands.' | '.
    "xargs -r -I {} sh -c 'docker inspect --format \"{{{{index .Config.Labels \\\"coolify.managed\\\"}}}}\" \"{}\" 2>/dev/null | grep -q true || docker rmi \"{}\" 2>/dev/null' || true";

In PHP double-quoted strings, { is not a special character and does not need escaping. {{{{ outputs literally as {{{{, not {{.

Generated Shell Command (actual)

docker inspect --format "{{{{index .Config.Labels \"coolify.managed\"}}}}" "image:tag"

Result

template parsing error: template: :1: unexpected "{" in command

The error goes to /dev/null, stdout is empty, grep -q true fails, and docker rmi executes — deleting the image despite it having the label.

Steps to Reproduce

Build an image with the label

echo 'FROM alpine
LABEL coolify.managed="true"' | docker build -t test-label -f - .

4 braces (what Coolify generates) — FAILS

docker inspect --format "{{{{index .Config.Labels "coolify.managed"}}}}" "test-label"

Output: template parsing error: template: :1: unexpected "{" in command

2 braces (correct) — WORKS

docker inspect --format "{{index .Config.Labels "coolify.managed"}}" "test-label"

Output: true

docker rmi test-label

Example Repository URL

No response

Coolify Version

v4.0.0-beta.463

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

Debian 13 (Linux 6.12)

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔍 TriageIssues that need assessment and prioritization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions