docker-compose up和stdin上的用户输入 [英] docker-compose up and user inputs on stdin

查看:430
本文介绍了docker-compose up和stdin上的用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释(也许提供解决方法)docker-compose的以下行为吗?

Can someone explain (and maybe give a workaround) for the following behavior of docker-compose ?

给出以下文件:

Dockerfile

FROM alpine:3.8

COPY ./entrypoint.sh /entrypoint.sh

ENTRYPOINT [ "/entrypoint.sh" ]

entrypoint.sh

#!/bin/sh

until [ ! -z "$PLOP" ]; do
    echo -n 'enter value here: '
    read PLOP
done

echo "Good ... PLOP is $PLOP"

exit 1

docker-compose.yml

version: '3.7'

services:
  plop:
    tty: true
    stdin_open: true
    image: webofmars/plop:latest

输出如下:

1) ./ entrypoint.sh

docker-stdin> ./entrypoint.sh
enter value here:
CASE1
Good ... PLOP is CASE1

似乎是确定

2) docker-stdin> docker run -it webofmars / plop

enter value here: CASE2
Good ... PLOP is CASE2

确定

3) docker-stdin> docker-compose run plop

enter value here: CASE3
Good ... PLOP is CASE3

似乎是 OK

4) docker-stdin> docker-compose up

Recreating docker-stdin_plop_1 ... done
Attaching to docker-stdin_plop_1 (last forever)

对于其中的某些情况似乎很奇怪,不好 我的用例

Which seems quite odd and NOT OK for my use case

我错过了什么吗?

推荐答案

docker在stdin上进行构图和用户输入

这是预期的行为。起来不是互动的。它可以启动
个容器,因此您无法在一个终端上打开
个stdin来容纳多个容器。

That is expected behaviour. up is not interactive. It can start multiple containers, so you can't have a single terminal that has stdin open for multiple containers.

但是您可以选择使用docker-compose。

But there is option to you can do with docker-compose.

在其他窗口中附加,当您从docker-compose开始时,您可以添加- d参数,它将在后台启动该docker。

Attach in different window, when you start with docker-compose up, you can add -d parameter and it will start that docker in background.

docker-compose up -d

然后只需附加该码头并输入值

Then just attach that docker and enter value

docker attach play_001_plop_1

单行命令:

docker-compose up -d && docker attach play_001_plop_1

这篇关于docker-compose up和stdin上的用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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