Docker Install MySQL
MySQL is the world’s most popular open source database. With its reliability, ease of use, and performance, MySQL has become the database of choice for Web applications.
1. Check the available MySQL versions
Visit the MySQL mirror repository at https://hub.docker.com/_/mysql?tab=tags.
You can view other versions of MySQL by Sort by, the default is the latest version mysql:latest.
You can also find other versions you want in the drop-down list –
In addition, we can use the docker search mysql command to see the available versions: docker search mysql:
$ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relati... 2529 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Crea... 161 [OK]
centurylink/mysql Image containing mysql. Optimized to be li... 45 [OK]
sameersbn/mysql 36 [OK]
google/mysql MySQL server for Google Compute Engine 16 [OK]
appcontainers/mysql Centos/Debian Based Customizable MySQL Con... 8 [OK]
marvambass/mysql MySQL Server based on Ubuntu 14.04 6 [OK]
drupaldocker/mysql MySQL for Drupal 2 [OK]
azukiapp/mysql Docker image to run MySQL by Azuki - http:... 2 [OK]
...
2. pull MySQL image
Here we pull the official mirror of the latest version:
$ docker pull mysql:latest
3. Check the local image
Use the following command to see if mysql is installed.
$ docker images
In the above image you can see that we have installed the latest (latest) version of the mysql image.
4. Running the container
Once the installation is complete, we can run the mysql container using the following command.
$ docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
Parameter description.
- -p 3306:3306 : Map the 3306 port of the container service to the 3306 port of the host, so that external hosts can access the MySQL service directly through host ip:3306.
- MYSQL_ROOT_PASSWORD=123456: Set the password of MySQL service root user.
5. Successful installation
Check whether the installation was successful by using the docker ps command.
The MySQL service can be accessed locally through root and password 123456.