Linux – Docker MySQL Image – CREATE MYSQL_USER

I am new to docker containers, and I am working on automating some MySQL tasks. By using bash scripts I am able to automate the creation and dump of Databases but now i am trying to create the new user getting input from the command line and it is not working. this is my script:

sudo docker run -it --link testing1:mysql --rm mysql/mysql-server:5.7.11 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" -e"CREATE USER 'docker'@'%' IDENTIFIED BY 'tester'"'

the error message i receive is :

  • Easy way to give docker container access to my local domains (.local, .dev)
  • What alternatives are there to using npm install --unsafe?
  • Default elasticsearch configuration for docker container
  • Accessing host usb device in docker for windows
  • How can I map a volume in a running docker container?
  • kapacitor: setting slack webhook URL in .tick file
    + E_BADARGS=65
    ++ which mysql
    + MYSQL=/usr/bin/mysql
    + sudo docker run -it --link testing1:mysql --rm mysql/mysql-server:5.7.11 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
    -e"CREATE USER docker@% IDENTIFIED BY tester"'
    mysql: [Warning] Using a password on the command line interface can be insecure.
    ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '% IDENTIFIED BY tester' at line 1

  • ERROR: compose.cli.main.main: 500 Internal Server Error: Cannot start container : [9] System error: not a directory
  • Docker centos7 image - unable to run apache
  • debug docker deamon with gdb or cgdb
  • Parse a variable with the result of a command in DockerFile
  • Searching for the most optimal solution with Django, Docker, virtualenv and structure of files [closed]
  • How to use docker image, without mounting the default volumes?
  • 3 Solutions collect form web for “Linux – Docker MySQL Image – CREATE MYSQL_USER”

    You need to enclose the % (to allow connections from any ip) in quotations.

    CREATE USER docker@'%' IDENTIFIED BY tester

    You can use this image as a template.

    I used
    mysql -e'GRANT ALL ON *.* TO user@"%" IDENTIFIED BY "password";'

    The solution was to set the ENV variables to get the user input like like this:
     and then this:     docker exec -it ctb /usr/bin/mysql -h -uroot -pmario123 -e "GRANT USAGE ON *.* TO ${USER}@${SOURCE} IDENTIFIED BY ${PASSWORD};"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.