Getting exit code out of docker-compose up

六月ゝ 毕业季﹏ 提交于 2020-05-09 06:36:09

问题


I have an issue getting an exit code out of docker-compose up.
I have the simplest container that runs a script that always exits with 1:

#!/usr/bin/env sh
exit 1

My Dockerfile:

FROM mhart/alpine-node:6
RUN mkdir /app
WORKDIR /app

And my docker-compose.yml:

version: '2'

services:
  test_container:
    container_name: test_container
    build: .
    volumes:
      - ${PWD}/run.sh:/app/run.sh
    entrypoint: ["/app/run.sh"]

When I run it with docker-compose -f docker-compose.yml up --force-recreate test_container I can see in logs:

Recreating test_container ... 
Recreating test_container ... done
Attaching to test_container
test_container exited with code 1

But when I echo $? I get 0.
Docker version 17.09.0-ce, build afdb6d4. Running on OSX 10.12.6.
Am I doing something wrong? Is that a known issue (I couldn't find anything out there)? Thanks.


回答1:


An option --exit-code-from SERVICE can be used with docker-compose up :)

From the documentation:

docker compose up

Options:
    --exit-code-from SERVICE   Return the exit code of the selected service container.
                               Implies --abort-on-container-exit.

    --abort-on-container-exit  Stops all containers if any container was stopped.
                               Incompatible with -d.

    -d                         Detached mode: Run containers in the background,
                               print new container names.
                               Incompatible with --abort-on-container-exit.


来源:https://stackoverflow.com/questions/47135390/getting-exit-code-out-of-docker-compose-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!