I followed a guide to setup docker and mysql (which i can no longer find) and everything went as expected. However i had to reinstall my OS, and now using the same commands doesn't do what i expect.
when creating a new container, then running "docker logs <container_name>", i expect to see a long string of log info, among which is a one time randomly generated password, which i can then use to change to a more memorable password.
However, i only get a short paragraph of logs with no password. I even copied commands line-for-line from an official mysql guide that explicitly states should show me a password, but doesn't.
Strangely, i realised docker needed an update, ran the update and found that running the log command now shows the password as expect! But when i tried it again on another container, the original problem returned. I haven't been able to recreate that success since.
I feel like i'm out of options for troubleshooting.
Here is all the code i ran, from installing docker to printing the log file.
#docker setup
sudo systemctl enable docker.service #start docker on startup
sudo systemctl start docker.service #start docker now
sudo docker pull mysql/mysql-server:latest
#create volumes
sudo docker volume create mysql-config
sudo docker volume create mysql-data
#container setup
sudo docker run --name master32-mysql -dp 3306:3306 -v mysql-data:/var/lib/mysql mysql/mysql-server:latest
sudo docker logs master32-mysql
Here are the logs i get after running the last command:
[Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
[Entrypoint] Starting MySQL 8.0.28-1.2.7-server
2022-01-27T00:52:41.963514Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 1
2022-01-27T00:52:41.969879Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-27T00:52:42.066204Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-27T00:52:42.219166Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-01-27T00:52:42.219204Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-01-27T00:52:42.233405Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-01-27T00:52:42.233414Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
Can anyone figure out why this isn't showing me a password? I'm aware that this command only shows the password one time, but i'm having this problem with every new container i make.
SOLUTION:
The main problem was that i was expecting every new container to generate it's own password, whithout realising that the password is stored in the volume which is linked to the container. To get a new password, i needed to create new volumes and link the new container with that instead.
I also needed to add '-e MYSQL_RANDOM_ROOT_PASSWORD=1' to the 'docker run' command.
CodePudding user response:
You haven't specified '-e MYSQL_RANDOM_ROOT_PASSWORD=1' on startup (docker run).
ref: entrypoint.
ref: docker hub docs
