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?

  • CHMOD in dockerfile for python
  • Squishing docker image without spinning a container
  • How to search images from private 1.0 registry in docker?
  • Docker API start container returns 404
  • How to mount volumes in docker release of openFOAM
  • Disable swap on a kubelet
  • Thanks 🙂

  • Xdebug Netbeans Php Docker
  • Run normal Win32 applications in Docker for Windows
  • Memory and CPU usage definition in docker cadvisor
  • Python docker-py Connection Refused
  • Docker - Failed to connect to localhost port 4000: Connection refused
  • How to fix output from tty of Docker for macOS vm?
  • 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.