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 :

  • What is the meaning of “sandbox” in “docker run” command?
  • How do I get my dreamweaver site to use my nginx docker container as a web test server?
  • Docker Compose raise an AccessDeniedExpcetion
  • Docker - ELK - vm.max_map_count
  • Create Docker container from image without starting it
  • Understanding vagrant with a docker provisioner
    + 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

  • Can I setup a remote spark server inside docker so that I can communicate with it locally?
  • Docker-machine ip in Dockerfile
  • Symfony2 app slow response on MacOS & Boot2Docker
  • Nginx behind Traefik Docker Swarm mode real ip
  • Why is my docker image size much bigger than my application?
  • Docker Engine command run --blkio-weight doesn't work
  • 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.