问题描述
有人可以解释(并可能给出解决方法) 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
我错过了什么吗?
推荐答案
这是预期的行为.up 不是交互式的.它可以启动多个容器,所以你不能有一个终端为多个容器打开标准输入.
但是您可以选择使用 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 和用户在标准输入上的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!