本文共 1664 字,大约阅读时间需要 5 分钟。
目录
选择一个指定的版本,或者直接拉去最新的mysql版本。
docker pull mysql
docker images
~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEmysql latest 4f1413420360 25 hours ago 545MB
最后冒号后面的是tag,就是版本,如果安装有多个版本的mysql是不是启动起来很方便。
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:8.0.22
docker ps查看启动的mysql进程
~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb8319bd56ae3 mysql "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 3306/tcp, 33060/tcp keen_swanson6a6cbd7a4dea mysql "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
–link 连接运行的容器 mysql.5.7.21 为之前首次运行时创建的容器名,冒号后为镜像名
~]# docker run -it --link mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -p'Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 9Server version: 8.0.22 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> select version();+-----------+| version() |+-----------+| 8.0.22 |+-----------+1 row in set (0.00 sec)mysql>
转载地址:http://bmhqj.baihongyu.com/