View available versions of MySQL
docker search mysql
Install MySQL image
docker pull mysql
Check the image (to see if the installation was successful)
docker images
Run MySQL
--name mysql-3306 is an alias, you can use it to start and stop MySQL. You can also use the automatically generated ID.
docker run -itd --name mysql-3306 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
Check if it is running successfully
docker ps
Enter the MySQL container
# Enter the MySQL container
docker exec -it mysql-3306 bash
# Enter MySQL and enter the password (123456)
mysql -u root -p