解決方法
console
1$ docker run -itd --name test_mysql -p 3306:3306 mysql:latest bash
このコマンドを修正します
- 最後の bash を取り除きます
 
- 環境変数 
MYSQL_ROOT_PASSWORD を与えます 
console
1docker run -itd -e MYSQL_ROOT_PASSWORD="passW0@d" --name test_mysql -p 3306:3306 mysql:latest
console
1$ docker run -itd -e MYSQL_ROOT_PASSWORD="passW0@d" --name test_mysql -p 3306:3306 mysql:latest
292cdd6876c0e4e0364609cae02e605d7d49f7b67b7c3b88359add7ffca7a685b
3$ docker exec -it test_mysql bash
4root@92cdd6876c0e:/# mysql -h 127.0.0.1 -u root -p
5Enter password: 
6Welcome to the MySQL monitor.  Commands end with ; or \g.
7Your MySQL connection id is 8
8Server version: 8.0.21 MySQL Community Server - GPL
9
10Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
11
12Oracle is a registered trademark of Oracle Corporation and/or its
13affiliates. Other names may be trademarks of their respective
14owners.
15
16Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
17
18mysql>
注: 入力が速すぎると MySQL の起動が間に合わずログインできません
原因
1
コマンドとして bash を与えてしまうと MySQL は起動しません
コマンドを与えなかったとき:
console
1root@3ca903dc86dd:/# ps -auxww
2USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
3mysql        1  1.5 11.7 2123748 359828 pts/0  Ssl+ 13:42   0:00 mysqld
4root        85  0.0  0.1   3868  3212 pts/1    Ss   13:42   0:00 bash
5root       599  0.0  0.0   7640  2652 pts/1    R+   13:43   0:00 ps -auxww
コマンドとして bash を与えたとき:
console
1root@94f930f8552c:/# ps -auxww
2USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
3root         1  0.0  0.1   3868  3160 pts/0    Ss+  13:44   0:00 bash
4root         6  0.0  0.1   3868  3264 pts/1    Ss   13:44   0:00 bash
5root       409  0.0  0.0   7640  2620 pts/1    R+   13:45   0:00 ps -auxww
2
環境変数 MYSQL_ROOT_PASSWORD は必須とされています:
mysql - Docker Hub
Environment Variables
MYSQL_ROOT_PASSWORD
This variable is mandatory
イメージは Docker Hub のトップもしくは GitHub の README.md を読むと使い方が書いてあります
特にDocker の公式イメージに関してはほとんどがしっかり書かれているので、
うまく行かないときは、これに目を通すのが最速で進捗するコツです
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/29 23:05 編集