Use docker to install mysql. After starting the container, mysql did not start

  docker, question

1. Installation

docker run -it -p 3306:3306 --name mysql1 -v ~/mysql/conf/my.cnf:/etc/mysql/my.cnf -v ~/mysql/logs:/logs -v ~/mysql/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d  docker.io/mysql  /bin/bash

2. Container startup

clipboard.png

3. After entering the container with attach, I did not see the mysql process

clipboard.png

1. It shows that mysql did not start, because the /bin/bash behind you has exposed the problem.

2. Try starting like this

$docker run -d mysql
 $docker exec -it $container_id /bin/bash

clipboard.png

The cause of the problem can be found in the official description of CMD and entrypoint instructions.

The following is my test results

#1. Simulate your effect. No error will be reported here, because mysqld was not executed for initialization and bash has already overwritten the instruction
 docker@default:~$ docker run -it mysql bash
 root@8b767c162afd:/# ps -aux | grep mysql
 root         7  0.0  0.0  11128   984 ?  S+   03:04   0:00 grep mysql
 
 #2. An error was reported because no -e environment parameter was added, which indicates that mysqld performed initialization and no environment variable was found.
 docker@default:~$ docker run -d mysql
 9212525aedf8f5586548fbc1d1e4fa130fd0ce294ac03c2d00a1c1d9945455a5
 docker@default:~$ docker exec -it 92 bash
 Error response from daemon: Container 9212525aedf8f5586548fbc1d1e4fa130fd0ce294ac03c2d00a1c1d9945455a5 is not running
 mysql-db
 docker@default:~$ docker logs 92
 error: database is uninitialized and password option is not specified
 You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
 docker@default:~$