(Method 1) Pulling a MySQL Docker Image
Pulling an Existing MySQL Docker Image
- Obtain the MySQL Docker image based on the MySQL version.
docker pull mysql/mysql-server:XX.XX.XX
XX.XX.XX indicates the MySQL version.

- View the local Docker image.
docker images

- Create and start a MySQL container.
docker run --name mysql-8.0.20 -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql/mysql-server:8.0.20
- --name: name of the container to be created
- -e: configuration information, which is used to configure the password of the root user of the MySQL database
- -p: port mapping, for example, mapping port 3306 of the host to port 3306 of mysql-8.0.20
- -d: ID of the container that is successfully started
- In the end, specify the image on which the container depends, for example, mysql/mysql-server:8.0.20.

- View the container status.
docker ps

- Access the container and connect to the MySQL database.
docker exec -it mysql-8.0.20 /bin/bash

Run the mysql -uroot -p123456 command to connect to the MySQL database.

Parent topic: Installing MySQL in a Docker Container