$ docker pull mysql
# 查看
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 0c27e8e5fcfa 6 hours ago 546MB
hello-world latest bf756fb1ae65 3 months ago 13.3kB
tag 是 MySQL 版本,比如可以填写 5.7,如果没有设置版本,Dcoker 会自动在本地检测有没有最新的,如果没有会自动去 Docker Hub 下载。该字段的选项如下
8.0.19,8.0,8,latest
5.7.29,5.7,5
5.6.47,5.6
1
2
3
4
# 查看当前容器运行状态
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
94e4725784bb mysql:8.0 "docker-entrypoint.s…"5 seconds ago Up 4 seconds 3306/tcp, 33060/tcp chitchat
root@94e4725784bb:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19 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>
4. 测试连接
第一种是使用 Navicat for MySQL 测试,Navicat 安装在宿主机的 win10系统中
$ docker exec -it chitchat bash root@cd6182d13e68:/# exitexit
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cd6182d13e68 mysql "docker-entrypoint.s…"11 hours ago Up 8 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp chitchat