The premise is that docker has been installed in the Linux system. If it is not installed, please refer to the following website:
https://blog.csdn.net/qq_2662385590/article/details/105665053?utm_source=app
, and then perform the following steps:
- You can use the docker search mysql command to check the available versions:
2. To pull the MySQL image, use the command: docker pull mysql
(this is to pull the latest version of the mysql image, if necessary, you can add the version number after mysql, Pull the corresponding mysql version. For example: docker pull mysql: 5.6, etc.)
- To check whether the image is successfully pulled, use the command: docker images
- Use the following command to run the mysql container:
docker run -itd --name mysql01 -p 3306:3306
-e MYSQL_ROOT_PASSWORD=123456 mysql
-p 3306:3306: Map port 3306 of the container service to port 3306 of the host. The external host can directly access the MySQL service through the host ip:3306.
MYSQL_ROOT_PASSWORD=123456: Set the password of the root user of the MySQL service.
--Name: Give the container a name and name it yourself.
5. Check whether the installation is successful through the docker ps command:
then you can access the MySQL service through the root user and password: 123456.