Rate This Document
Findability
Accuracy
Completeness
Readability

(Method 1) Pulling a MySQL Docker Image

Pulling an Existing MySQL Docker Image

  1. 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.

  2. View the local Docker image.
    docker images

  3. 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.

  4. View the container status.
    docker ps

  5. 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.