从Docker中获取退出代码 - 组成

时间:2017-11-06 11:00:16

标签: docker docker-compose

我在退出docker-compose up时遇到问题 我有一个最简单的容器,它运行一个总是以1:

退出的脚本
#!/usr/bin/env sh
exit 1

我的Dockerfile:

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

我的docker-compose.yml:

version: '2'

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

当我使用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

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

1 个答案:

答案 0 :(得分:3)

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

来自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.
相关问题