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?

  • How to pull docker image from docker hub private registry into Azure Container Service (ACS)?
  • Cannont create lxc container with ubuntu template using lxc 1.0.0.alpha 1 on Ubuntu 13.04 Raring version
  • Running build via gitlab ci / docker
  • Docker exposed ports are not available
  • unable to connect through SSH key to bluemix container
  • Docker build seems to not see requirements.txt even though it's in same directory
  • Thanks 🙂

  • Running Client program and API in same Docker Machine
  • Docker compose and REST config
  • Docker + Wordpress + Traefik
  • How to configure docker for multiple user groups (sudo and non-sudo) with copy/commit restrictions?
  • docker commit not saving changes made by java installation
  • Boot2Docker on Mac - Accessing Local Files
  • 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 mysql etc…

    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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.