Home  >  Article  >  Database  >  Detailed explanation of how to use DockerHub’s official MySQL image

Detailed explanation of how to use DockerHub’s official MySQL image

黄舟
黄舟Original
2017-01-18 11:35:141925browse

Mysql relational database management system

MySQL is an open source small relational database management system developed by the Swedish MySQL AB company. MySQL is widely used in small and medium-sized websites on the Internet. Due to its small size, fast speed, low total cost of ownership, and especially the characteristics of open source, many small and medium-sized websites choose MySQL as their website database in order to reduce the total cost of website ownership.


#MySQL is a widely used open source relational database, so how to obtain the Mysql Docker image? Let’s take a look at how to use DockerHub’s official MySQL image through this article. Friends in need can refer to it.

Preface

Recently I have been trying to make a centos-based MySQL image based on the official centos image. However, after production, it was found that the image size has exceeded 1.5G, which is too bloated for ordinary Docker images. The mysql image officially provided by Docker Hub is only 324MB. At present, I haven't found any good way to reduce the size of the image I made, so I will use the official one first!

docker pull mysql:5.7

How to use this Docker image?

1. Start a Mysql Server container (default port 3306)

docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

2. Start another container and access the Mysql server through a link

docker run --name some-app --link mysql:mysql -d application-that-uses-mysql

3. Start another Container, access the Mysql server through the Mysql command line

docker run -it --link mysql:mysql --rm mysql:5.7 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT"
 -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'

4. Enter the server console

docker exec -it mysql bash

5. View the Mysql server log

docker logs mysql

For more information, please refer to the official website for details :https://hub.docker.com/_/mysql/.

The above is a detailed explanation of how to use DockerHub’s official MySQL image. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn