简体   繁体   English

为什么在创建新的 mysql 容器时 docker 不会生成密码?

[英]Why won't docker generate a password when creating a new mysql container?

I followed a guide to setup docker and mysql (which i can no longer find) and everything went as expected.我按照指南设置 docker 和 mysql(我再也找不到),一切都按预期进行。 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.当创建一个新容器,然后运行“docker logs <container_name>”时,我希望看到一长串日志信息,其中是一个一次性随机生成的密码,然后我可以用它来更改一个更容易记住的密码。

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.我什至从官方 mysql 指南中逐行复制命令,该指南明确指出应该向我显示密码,但没有。

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.奇怪的是,我意识到 docker 需要更新,运行更新并发现运行日志命令现在按预期显示密码,但是当我在另一个容器上再次尝试时。 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 到打印日志文件。

#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.我还需要在“docker run”命令中添加“-e MYSQL_RANDOM_ROOT_PASSWORD=1”。

You haven't specified '-e MYSQL_RANDOM_ROOT_PASSWORD=1' on startup ( docker run ).您没有在启动时指定'-e MYSQL_RANDOM_ROOT_PASSWORD=1'( docker run )。

ref: entrypoint .参考: 入口点

ref: docker hub docs参考: docker 集线器文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM