Docker Community Forums

Share and learn in the Docker community.

Docker-compose script with prompt.... better solution?

(Pir81) #1

Hi, I have a bash script to start various docker-compose.yml(s)

One of these compose instances is docker-compose.password.yml to create a password file for mysql. For that I need to prompt the user to input a user name and then run a service in docker (that is actually not running).

basically the only way I can think of to accomplish this is run the docker in idle state, exec the command and close the docker. Is there a better way?

My solution:


version: '2'
      top -b -d 3600


docker-compose -f docker-compose.password.yml up -d

prompt the user by my bash script outside of docker for the credentials
read -p "Input user name.echo $’\n> ’" username

and send it to the running docker

docker exec createpw /bin/bash -c "mysql_config_editor set --user=${username} --password"

and then docker-compose down

Tried and not working:
I tried to have just a small subscript prompting for the input right under command

  /bin/bash /somewhere/

This did produce the file, but the user was an empty string, as the prompt didn’t stop the docker execution. It didn’t matter if I used compose -d or not.

Any suggestions are welcome. Thanks.