从 docker

编程入门 行业动态 更新时间:2024-10-28 12:23:26
本文介绍了从 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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 04:05:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/796057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!