docker-compose up and user inputs on stdin

旧时模样 提交于 2020-01-01 05:32:22

问题


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

Given the following files :

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

The output will be the following:

1) ./entrypoint.sh

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

Which seems OK

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

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

Which seems OK

3) docker-stdin> docker-compose run plop

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

Which seems 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

Did i missed something ?


回答1:


docker compose up and user inputs on 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.

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

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

Single line command:

docker-compose up -d && docker attach play_001_plop_1


来源:https://stackoverflow.com/questions/53106678/docker-compose-up-and-user-inputs-on-stdin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!