微信搜索 zze_coding 或扫描 👉 二维码关注我的微信公众号获取更多资源推送:

1、拉取 mysql5.6 镜像文件:

[root@localhost ~]# docker pull mysql:5.6
Trying to pull repository ... 
5.6: Pulling from
27833a3ba0a5: Already exists 
864c283b3c4b: Already exists 
cea281b2278b: Already exists 
8f856c14f5af: Already exists 
9c4f38c23b6f: Already exists 
688342d0934f: Pull complete 
1f90d0188066: Pull complete 
6d31565f1a00: Pull complete 
12062e921a90: Pull complete 
066ae780ca9a: Pull complete 
f6eece737bcc: Pull complete 
Digest: sha256:de2913a0ec53d98ced6f6bd607f487b7ad8fe8d2a86e2128308ebf4be2f92667
Status: Downloaded newer image for

2、创建并运行一个 mysql5.6 的容器:

[root@localhost ~]# docker run --name mysql56 -e MYSQL_ROOT_PASSWORD=root -d -p 3306:3306 mysql:5.6 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

3、通过 mysql 容器提供的客户端功能测试连接 mysql 容器:

[root@localhost ~]# docker run -it --link mysql56 --rm mysql:5.6 sh -c 'exec mysql -hmysql56 -uroot -proot'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.43 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


Copyright: 采用 知识共享署名4.0 国际许可协议进行许可


Buy me a cup of coffee ☕.