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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With