Ubunto docker sh mysql script run
I have a script which build my docker env.
I have this line:
docker exec -it guac-mysql /bin/bash mysql -u root -p123456 CREATE DATABASE guacamole; CREATE USER 'guacamole' IDENTIFIED BY 123456; GRANT SELECT,INSERT,UPDATE,DELETE ON guacamole.* TO 'guacamole'; FLUSH PRIVILEGES; quit
When I run, the script gets in the bash on the container, but the other lines dont run, I just have to run them one by one.
How can I exec and then inject the script?
One Solution collect form web for “Ubunto docker sh mysql script run”
you can’t run this as a single script. the docker exec command will create a shell into the container. it won’t run the rest of it until you exit the container. then it will run the
you need to run
docker exec -it guac-mysql /bin/bash
and then you can create a separate script to run the
mysql command within the container itself
but your current script won’t work. again, it will run
mysql and then wait for that to exit before running the
create database, etc.
see the docs on executing scripts from a file: https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html