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?

  • Docker recreates directories on host after reboot
  • Connection between docker container
  • Unable to install node 7.5.0
  • Linux Namespaces: Is it possible for a network namespace to exist without being associated with a process?
  • Connect to a docker host that is managed by dockercloud-agent
  • Docker Compose : NodeJS + MongoDB
  • Thanks 🙂

  • ECS network host mode and links = CannotCreateContainerError: Container already exists
  • How to do a custom deploy using ssh with Travis CI?
  • Forward container port set by external service at runtime
  • Issue regarding the Dockerfile creation
  • Sharing installed tools from one container to all containers with docker compose
  • How can I determine if a specific tag is available for an image
  • 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.