从docker中获取退出代码-撰写

Dan*_*zyk 2 docker docker-compose

我在退出代码时遇到问题docker-compose up
我有运行脚本的最简单的容器,该脚本始终以1退出:

#!/usr/bin/env sh
exit 1
Run Code Online (Sandbox Code Playgroud)

我的Dockerfile:

FROM mhart/alpine-node:6
RUN mkdir /app
WORKDIR /app
Run Code Online (Sandbox Code Playgroud)

和我的docker-compose.yml:

version: '2'

services:
  test_container:
    container_name: test_container
    build: .
    volumes:
      - ${PWD}/run.sh:/app/run.sh
    entrypoint: ["/app/run.sh"]
Run Code Online (Sandbox Code Playgroud)

当我运行它时,docker-compose -f docker-compose.yml up --force-recreate test_container我可以在日志中看到:

Recreating test_container ... 
Recreating test_container ... done
Attaching to test_container
test_container exited with code 1
Run Code Online (Sandbox Code Playgroud)

但是当echo $?我得到0
Docker版本17.09.0-ce,构建afdb6d4。在OSX 10.12.6上运行。
难道我做错了什么?那是一个已知问题(我在那里找不到任何东西)吗?谢谢。

Dan*_*zyk 5

选项--exit-code-from SERVICE可以与docker-compose up一起使用:)

文档中

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.
Run Code Online (Sandbox Code Playgroud)