community.docker
community.docker copied to clipboard
docker_compose restarts even initially created containers
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
- [X] I agree to follow the Ansible Code of Conduct