从 docker-compose up 中获取退出代码 [英] Getting exit code out of docker-compose up

查看:47
本文介绍了从 docker-compose up 中获取退出代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 docker-compose up 中获取退出代码时遇到问题.
我有一个最简单的容器,它运行一个总是以 1 退出的脚本:

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

我的 Dockerfile:

My Dockerfile:

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

还有我的 docker-compose.yml:

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"]

当我运行它时:

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 上运行.
难道我做错了什么?这是一个已知问题吗(我在那里找不到任何东西)?

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)?

推荐答案

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

An option --exit-code-from SERVICE can be used with 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.

这篇关于从 docker-compose up 中获取退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆