Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose up and user inputs on stdin

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 ?

like image 819
webofmars Avatar asked Nov 01 '18 17:11

webofmars


1 Answers

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
like image 198
Edmhs Avatar answered Oct 19 '22 20:10

Edmhs