How to use the official MySQL image of DockerHub, dockerhubmysql
Preface
Recently, I have been trying to create a centos-based MySQL Image Based on the official centos image. However, after the image is created, the image size exceeds 1.5 GB, which is too bloated for common Docker images. The official mysql image provided by Docker Hub is 324 MB. At present, I have not found any good method to reduce the size of my image, so I should first use the official one!
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 and 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. Go to the server console
docker exec -it mysql bash
5. View Mysql server logs
docker logs mysql
For more information, see https://hub.docker.com/_/mysql /.
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.