Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_compose restarts even initially created containers #682

Open
1 task done
sistason opened this issue Sep 10, 2023 · 3 comments
Open
1 task done

docker_compose restarts even initially created containers #682

sistason opened this issue Sep 10, 2023 · 3 comments
Labels
bug Something isn't working docker-compose-v1 Docker Compose v1

Comments

@sistason
Copy link

sistason commented Sep 10, 2023

Summary

I am unsure if it's a bug or just an (for me) unexpected behaviour:

When using docker_compose with restarted=yes, the freshly container gets restarted right after creation, often breaking entrypoints and such.

Issue Type

Bug Report

Component Name

docker_compose

Ansible Version

2.11.1 with python 3.10

Community.general Version

community.general 7.0.1

Configuration

not applicable

OS / Environment

debian bullseye

Steps to Reproduce

- copy:
    dest: /srv/foo/docker-compose.yml
    content: |
      version: "3"
      services:
        db:
          image: mysql:5.7
          environment:
            MYSQL_DATABASE: foo
            MYSQL_ROOT_PASSWORD: "bar"
  register: _composefile
- docker_compose:
    project_src: "/srv/foo"
    project_name: "foo"
    state: "present"
    restarted: "{{ _composefile.changed }}"

Expected Results

I expected restarted=yes to not restart containers which were just created, as the whole point of restarting is that the container runs anew with all previously changed things (mostly changed mounted configfiles, which compose does not know about).

Actual Results

In the example, the mysql entrypoint creating the table gets interrupted, leading to a broken mysql. But I'd like to keep the restart functionality, depending on changed config/compose files.

handlers have the same problem, but the other way around - the handler needs restarted: yes, but shouldn't run initially. Do I really have to find out if the container did not exist before, and guard the restarted against that?

I'd suggest restarted does not restart services which it just now started.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the bug Something isn't working label Sep 10, 2023
@felixfontein felixfontein transferred this issue from ansible-collections/community.general Sep 10, 2023
@felixfontein felixfontein added the docker-compose-v1 Docker Compose v1 label Sep 10, 2023
@felixfontein
Copy link
Collaborator

Good question. The documentation of the state option isn't fully clear whether docker-compose up is ran before docker-compose stop or docker-compose restart or not - the implementation does exactly that, though. I guess part of it is because the implementation wants to make sure that the service is actually in a correct state (i.e. all containers are up and running with the correct configuration etc.) before restating. Changing this in a sensible way is not so easy, I guess.

@jacobw
Copy link

jacobw commented Sep 11, 2023

I have a similar issue.

I use a handler with restarted: true which I expect to start (up) the containers if they are not running already (usually on first deploy), and restart them if they are already running. This is breaking a project that needs to do some things on first run only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docker-compose-v1 Docker Compose v1
Projects
None yet
Development

No branches or pull requests

4 participants