You can change it from the running container using the docker exec session , as described in the section β Connecting to MySQL Server from the container β
Once the server is ready, you can start the mysql client in the MySQL Server container that you just started and connect it to MySQL Server.
Use the docker exec -it to start the mysql client in the Docker container that you started, for example:
docker exec -it mysql1 mysql -uroot -p
When prompted, enter the generated root password (see instructions above on how to find it). Since the MYSQL_ONETIME_PASSWORD option is MYSQL_ONETIME_PASSWORD to MYSQL_ONETIME_PASSWORD by default, after you start the server container with the command example above and connect the mysql client to the server, you must reset the server root password by executing this statement for MySQL 5.7 and higher:
mysql> update user set authentication_string=password('new_password') where user='root';
or alternatively run
mysql> SET PASSWORD FOR 'root' = PASSWORD('new_password');
For MySQL 5.7 and earlier, run
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
Replace newpassword password of your choice. After resetting the password, the server is ready to use.
Note that the above command will only change the password for the root user connecting from localhost. You can verify this with the command:
select * from mysql.user;
To change the password for the root user from all hosts, use:
ALTER USER 'root'@'%' IDENTIFIED BY 'newpassword';
Then, as described in hub.docker.com/mysql , don't forget the docker secrets :
As an alternative to transferring sensitive information through environment variables, _FILE can be added to the previously listed environment variables, as a result of which the initialization script loads the values ββof these variables from the files present in the container.
In particular, it can be used to load passwords from Docker secrets stored in /run/secrets/<secret_name> .
For instance:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql-root -d mysql:tag