mysql_config_editor with docker

Hi I’m trying to use mysql_config_editor tools directly in my Dockerfile:

FROM mysql
RUN mysql_config_editor set --login-path=local --user=root --password

But this command ask the user to enter the password. Is there a way to set the password directly from the Dockerfile knowing that it is not possible to set the password directly in the command line.

  • Rebuild same docker image with only the additional changes in the Dockerfile
  • Docker, Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • REST request across networks
  • Unable to connect to docker container
  • Docker ignores local project
  • Elastic Beanstalk with Docker and Persistent Storage
  • root@d80484a3177f:~# mysql_config_editor set --login-path=local --user=root --password                   
    Enter password: 
    
    root@d80484a3177f:~# mysql_config_editor set --login-path=local --user=root --password=root
    mysql_config_editor: [ERROR] mysql_config_editor: option '--password' cannot take an argument
    

    Thanks

  • Run multiple instances on a Mesos slave node
  • Dockerfile: $HOME is not working with ADD/COPY instructions
  • How to let a non-root process in a Linux docker container bind to a <1024 port?
  • Docker :- Creating Databases in Postgresql Docker Container
  • Wildfly: AMQ214016: Failed to create netty connect ion java.nio.channels.UnresolvedAddressException from client on natted network
  • How to yank to host clipboard from inside a Docker container?
  • 2 Solutions collect form web for “mysql_config_editor with docker”

    I can think of 2 approaches:

    1. Use Interactive mode and commit changes
      To do this you will start a container from mysql image with -it switch.

    then you will do your changes.

    and commit changes with docker commit to create a new Image from container.

    1. Blank root password for the duration of docker file.

      MYSQL_ALLOW_EMPTY_PASSWORD=yes

    The above is environment variable that allows blank password. Make sure you change it to default after you are done.

    Hope this helps.

    You can use expect to do this :

    This is your Dockerfile :

    FROM mysql:5.7
    
    RUN apt-get update && apt-get --no-install-recommends --no-install-suggests -y install expect
    
    ENV MYSQL_ROOT_PASSWORD "secure_root_password"
    
    ADD mysql_config.sh /root/mysql_config.sh
    RUN cd /root && ./mysql_config.sh $MYSQL_ROOT_PASSWORD
    

    And this is mysql_config.sh :

    #!/usr/bin/expect
    
    set pwd [lindex $argv 0];
    
    spawn mysql_config_editor set --login-path=local --host=localhost --user=root --password
    expect -nocase "Enter password:" {send "${pwd}\r"; interact}
    

    Now you can connect directly to MySQL :

    $ docker exec -it your-mysql-container mysql --login-path=local
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 6
    Server version: 5.7.18 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Maybe it’s not the cleanest way, but it works !

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