docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.6k stars 5.18k forks source link

docker compose start possible stdout issue #10683

Open Mondo1111 opened 1 year ago

Mondo1111 commented 1 year ago

Description

I believe there is an issue with the command docker compose start. While the Python command subprocess.check_output waits for the end of the command to continue the script, the script continues even if docker compose start didn't finish to run.

Steps To Reproduce

  1. OS Ubuntu 18.04.6 LTS (Bionic Beaver)
  2. Run the script via crontab
  3. Run the script like /usr/bin/env python3
  4. The script:
    
    #!/usr/bin/env python3

import subprocess import os from colorama import Fore from colorama import Style

dockers_stop = ["docker compose -f /usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/docker-compose_v3_alpine_pgsql_latest_flexilab.yaml --profile flexilab stop"] tar_command = ["tar -czvf /zabbix-backup/backup-zabbix-pgsql.tar.gz /usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/"] dockers_start = ["docker compose -f /usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/docker-compose_v3_alpine_pgsql_latest_flexilab.yaml --profile flexilab start"]

docker_commands = [dockers_stop, tar_command, dockers_start]

print(f"{Fore.RED}Zabbix backup!!! Don't restart Zabbix\n The result of the tar will be shown in the end of the archiving{Style.RESET_ALL}")

for docker_user_commands in docker_commands: for command in docker_user_commands: print(f"{Fore.GREEN}Command inserted:{Style.RESET_ALL}", command) output = subprocess.check_output(command, shell=True, universal_newlines=True).splitlines() print(*output, sep='\n')

print(f"{Fore.RED}Zabbix backup is done!!!{Style.RESET_ALL}")


### Compose Version

```Text
Docker Compose version v2.6.1

Docker Environment

Client:

Context:    default

Debug Mode: false

Plugins:

  app: Docker App (Docker Inc., v0.9.1-beta3)

  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)

  compose: Docker Compose (Docker Inc., v2.6.1)

  scan: Docker Scan (Docker Inc., v0.17.0)

Server:

Containers: 5

  Running: 4

  Paused: 0

  Stopped: 1

Images: 17

Server Version: 20.10.17

Storage Driver: overlay2

  Backing Filesystem: extfs

  Supports d_type: true

  Native Overlay Diff: true

  userxattr: false

Logging Driver: json-file

Cgroup Driver: cgroupfs

Cgroup Version: 1

Plugins:

  Volume: local

  Network: bridge host ipvlan macvlan null overlay

  Authorization: hbm

  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog

Swarm: inactive

Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc

Default Runtime: runc

Init Binary: docker-init

containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6

runc version: v1.1.4-0-g5fd4c4d

init version: de40ad0

Security Options:

  apparmor

  seccomp

   Profile: default

Kernel Version: 4.15.0-200-generic

Operating System: Ubuntu 18.04.6 LTS

OSType: linux

Architecture: x86_64

CPUs: 6

Total Memory: 23.54GiB

Docker Root Dir: /local/docker

Debug Mode: false

Registry: https://index.docker.io/v1/

Labels:

Experimental: false

Insecure Registries:

  127.0.0.0/8

Live Restore Enabled: false

WARNING: No swap limit support

Anything else?

Faulty output snippet:

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/ol/conf/etc/httpd/conf.d/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/ol/conf/etc/httpd/conf.d/99-zabbix.conf

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/ol/build.sh

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/ol/README.md

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/DockerfileContainer zabbix-docker-db_data_pgsql-1  Starting

Container zabbix-docker-postgres-server-1  Starting

Container zabbix-docker-zabbix-agent-1  Starting

Container zabbix-docker-zabbix-agent-1  Started

Container zabbix-docker-postgres-server-1  Started

Container zabbix-docker-zabbix-server-1  Starting

Container zabbix-docker-db_data_pgsql-1  Started

Container zabbix-docker-zabbix-server-1  Started

Container zabbix-docker-zabbix-web-nginx-pgsql-1  Starting

Container zabbix-docker-zabbix-web-nginx-pgsql-1  Started

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/docker-entrypoint.sh

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/.dockerignore

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/zabbix/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/zabbix/apache_ssl.conf

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/zabbix/apache.conf

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/zabbix/web/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/zabbix/web/maintenance.inc.php

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/zabbix/web/zabbix.conf.php

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/php8/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/php8/conf.d/

/usr/local/data/zabbix-docker-postrgresql-6.0/zabbix-docker/Dockerfiles/web-apache-mysql/alpine/conf/etc/php8/conf.d/99-zabbix.ini
glours commented 1 year ago

Hello @Mondo1111 I saw you're using a one year old version of Compose, within a year we did a bunch of improvements and corrections. Can you try to reproduce your issue with a more recent version of Compose please. Here a link to the last version

laurazard commented 1 year ago

@Mondo1111 From your snippet, it looks like your tar command is the one that hasn't exited before docker compose start starts running, right?

Mondo1111 commented 1 year ago

Hi,

Sorry for the late reply.

You're right @laurazard , that's what the snippet shows. It is actually a different behaviour than usual.

Thank you @glours for the insight. It is currently running in production, so I will have to test it on another environment.