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

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

问题描述

有人可以解释(并可能给出解决方法) 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

看起来好的

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 组合和用户输入在标准输入

这是预期的行为.up 不是交互式的.它可以启动多个容器,所以你不能有一个终端为多个容器打开标准输入.

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 up 时,你可以添加 -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 和用户在标准输入上的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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