目录mysql
1、pull官方镜像sql
2、查看镜像docker
4、如何登录到客户端spa
1、pull官方镜像
选择一个指定的版本,或者直接拉去最新的mysql版本。code
docker pull mysql
2、查看镜像
docker images进程
~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 4f1413420360 25 hours ago 545MB
3、运行容器(开启mysql服务)
最后冒号后面的是tag,就是版本,若是安装有多个版本的mysql是否是启动起来很方便。input
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:8.0.22
docker ps查看启动的mysql进程it
~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b8319bd56ae3 mysql "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 3306/tcp, 33060/tcp keen_swanson 6a6cbd7a4dea mysql "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
4、如何登录到客户端
–link 链接运行的容器 mysql.5.7.21 为以前首次运行时建立的容器名,冒号后为镜像名io
~]# 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 9 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. 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>