Skip to content

docker_compose: Fix idempotence#1054

Closed
sboyd-m wants to merge 1 commit into
puppetlabs:mainfrom
sohonet:sohonet/fix-compose-exists
Closed

docker_compose: Fix idempotence#1054
sboyd-m wants to merge 1 commit into
puppetlabs:mainfrom
sohonet:sohonet/fix-compose-exists

Conversation

@sboyd-m

@sboyd-m sboyd-m commented Apr 29, 2026

Copy link
Copy Markdown

Summary

When the module checks for running containers, it runs something like the following:

/usr/bin/docker ps --format '{{.Label "com.docker.compose.service"}}-{{.Image}}' --filter label=com.docker.compose.project=name_of_resource

The output of which appears similar to as follows:

web-name_of_resource-web
celery-name_of_resource-celery
celery-beat-name_of_resource-celery-beat
flower-mher/flower:2.0
postgres-postgres:15-alpine
redis-redis:7-alpine

However, when getting the expected name of the image to check, the module hardcodes an underscore, resulting in things like web-name_of_resource_web.

When the counting is done to check for existence, this does not match, so nothing is found, so the module tries to recreate the whole composition.

Root cause

The root cause is simply a change on Docker's side. On Ubuntu 24.04, when installing from Canonical's packages, Docker compose is v1.29 and the separator is an underscore. If you install with the this module, you get much newer versions, and the separator is a hyphen.

Checklist

  • 🟢 Spec tests.
  • 🟢 Acceptance tests.
  • Manually verified. (For example puppet apply)

Reproduce:

On any Ubuntu (I tested on 18.04, 20.04, 22.04, 24.04):

  1. Create some test files (I did this all as root, in root's homedir)

Dockerfile:

FROM python:3.12-alpine
WORKDIR /code
COPY app.py .
RUN pip install Flask
EXPOSE 5000
CMD ["flask", "run"]

app.py:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

compose.yaml:

services:
  bob:
    container_name: bob
    network_mode: host
    restart: on-failure
    build: .
  redis:
    container_name: dole
    image: redis:alpine
    restart: on-failure

test.pp

include docker::compose

docker_compose { 'webapp':
  ensure        => present,
  compose_files => ["/root/compose.yaml"],
}
  1. puppet module install puppetlabs-docker --version 10.4.0
  2. puppet apply test.pp
  3. At this point, apply Puppet a few times. Notice it recreates the composition every time.
  4. sed -i.bak 's,image = "#{name}_#{service_name}",image = "#{name}-#{service_name}",' /etc/puppetlabs/code/environments/production/modules/docker/lib/puppet/provider/docker_compose/ruby.rb
  5. At this point, note the composition is not recreated.

When the module checks for running containers, it runs something like
the following:

```
/usr/bin/docker ps --format '{{.Label "com.docker.compose.service"}}-{{.Image}}' --filter label=com.docker.compose.project=name_of_resource
```

The output of which appears similar to as follows:

```
web-name_of_resource-web
celery-name_of_resource-celery
celery-beat-name_of_resource-celery-beat
flower-mher/flower:2.0
postgres-postgres:15-alpine
redis-redis:7-alpine
```

However, when getting the *expected* name of the image to check, the
module hardcodes an underscore, resulting in things like
`web-name_of_resource_web`.

When the counting is done to check for existence, this does not match,
so nothing is found, so the module tries to recreate the whole
composition.
@sboyd-m sboyd-m requested a review from a team as a code owner April 29, 2026 18:19
@CLAassistant

CLAassistant commented Apr 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kenyon

kenyon commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #990.

@jst-cyr

jst-cyr commented Jun 10, 2026

Copy link
Copy Markdown
Member

Thank you for submitting @sboyd-m ! @kenyon correctly flagged this as a duplicate of #990 , so I'll close this particular PR as a duplicate and we will use the other PR for resolving this issue.

@jst-cyr jst-cyr closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants