我在退出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上运行
难道我做错了什么?这是一个已知的问题(我无法找到任何东西)?感谢。
答案 0 :(得分:3)
选项--exit-code-from SERVICE
可与docker-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.