从docker获取退出代码 – 组成

我有一个问题得到docker-compose up出口代码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运行它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上运行。
难道我做错了什么? 这是一个已知的问题(我什么也找不到)? 谢谢。

--exit-code-from SERVICE中可以使用一个选项--exit-code-from SERVICE -compose 🙂

从文档 :

 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.