-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[BUG] compose up --wait exits 1 on init containers successfully completing #10596
Comments
There's unfortunately no way to declare your |
Hit this as well - does anyone have some workaround, please? |
I'm using this:
|
We use the docker compose as part of test setup - the or-true approach will effectively void ANY kind of error coming from the stack (not only the "harmless one"). |
Yes, it will. It will also make your test setup complete without errors (until this issue is fixed). The choice is yours :) |
what about just using the return code of the "pseudo service" process? if it's 0, then do not consider it as an error by the |
While this is not to argue that $ docker compose -f - up --wait <<'EOF'
services:
sleepy:
image: alpine
command: sleep 5
EOF
[+] Running 1/1
✔ Container waitish-sleepy-1 Healthy
$ echo $?
0
... there is also this page of documentation: Well, noting that ... there is an unfortunate limitation - run can only run one service - and ... extrapolating a bit, here's an example of what works now: # compose.yaml
services:
postgres:
image: postgres
environment:
POSTGRES_PASSWORD: password
healthcheck:
test: pg_isready
start_interval: 1s
start_period: 30s
psql:
profiles:
- .init
image: postgres
depends_on:
postgres:
condition: service_healthy
environment:
PGUSER: postgres
PGDATABASE: postgres
PGPASSWORD: password
entrypoint: psql -h postgres
command: -c \\conninfo
init:
profiles:
- .init
build:
dockerfile_inline: FROM scratch
init: true
entrypoint: /sbin/docker-init --version
depends_on:
psql:
condition: service_completed_successfully
$ docker compose run init
[+] Creating 3/3
✔ Network init_default Created 0.1s
✔ Container init-postgres-1 Created 0.1s
✔ Container init-psql-1 Created 0.1s
[+] Running 2/2
✔ Container init-postgres-1 Healthy 5.8s
✔ Container init-psql-1 Started 0.3s
tini version 0.19.0 - git.de40ad0
$ echo $?
0
# postgres is started because of the init -> psql -> postgres depends-ons
# and init could depend on a number of other services/"tasks"/one-offs
# the alternative would be to run each needed "task"/one-off sequentially, but that requires remembering them
$ docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
init-postgres-1 postgres "docker-entrypoint.s…" postgres 2 minutes ago Up 2 minutes (healthy) 5432/tcp
# next, up --wait, could start the rest and it would ignore psql and init because they are behind a profile;
# it could even be done by the init itself if you can assume enough (e.g. about docker's sock)
$ docker compose up --wait
[+] Running 1/1
✔ Container init-postgres-1 Healthy
$ echo $?
0
# PS
$ docker compose --profile .init logs psql
psql-1 | You are connected to database "postgres" as user "postgres" on host "postgres" (address "172.28.0.2") at port "5432".
|
Just hit this too and confirmed this is still a problem as of 2.24.7. This thread doesn't seem to lack examples, but I'll include mine just in case too. services:
minio-create-buckets:
image: quay.io/minio/mc
environment:
MINIO_HOST: http://minio:9000
MINIO_ACCESS_KEY: minio-user
MINIO_SECRET_KEY: minio-password
entrypoint:
- bash
- -c
- |
mc alias set minio http://minio:9000 minio-user minio-password
mc mb minio/bucket-1
mc mb minio/bucket-2
mc anonymous set public minio/bucket-1
mc anonymous set public minio/bucket-2
echo "Hello, world!" > sample.txt
mc cp sample.txt minio/bucket-1
mc cp sample.txt minio/bucket-2
networks:
- docker-network
depends_on:
minio:
condition: service_healthy
minio:
image: quay.io/minio/minio
environment:
MINIO_ROOT_USER: minio-user
MINIO_ROOT_PASSWORD: minio-password
command: server /data --console-address ":9001"
ports:
- 9000:9000
- 9001:9001
networks:
- docker-network
healthcheck:
test: ["CMD", "mc", "ping", "--exit", "local"]
start_period: 10s
start_interval: 1s
interval: 3s
timeout: 2s
retries: 5
networks:
docker-network: |
@ndeloof who could be an appropriate reviewer for the PR mentioned above, ty 🙂 |
what about this format |
@idsulik |
why? |
Description
When using
docker compose up --wait
, where I have an init container that populates some data and then exits (0), docker compose will exit 1.If any other container depends on the init container finishing, it will exit properly, as described/exampled in this PR: #9572. In my situation however, there is no container that runs a service that depends on the init container finishing.
Steps To Reproduce
docker-compose.yml example:
Run docker compose/print exit code:
Compose Version
Docker Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: