Centos7 的Docker上如何安装MySQL

来源:互联网 发布:淘宝童装拍照技巧 编辑:程序博客网 时间:2024/05/16 12:43

1.进入Linux后,使用Docker命令下载MySQL,命令如:

     docker pull mysql:5.7

运行该命令后,则会显示以下日志:

[root@localhost ~]# docker pull mysql:5.75.7: Pulling from library/mysqlad74af05f5a2: Pull complete 0639788facc8: Pull complete de70fa77eb2b: Pull complete 724179e94999: Pull complete 50c77fb16ba6: Pull complete d51f459239fb: Pull complete 937bbdd4305a: Pull complete 35369f9634e1: Pull complete f6016aab25f1: Pull complete 5f1901e920da: Pull complete fdf808213c5b: Pull complete Digest: sha256:96edf37370df96d2a4ee1715cc5c7820a0ec6286551a927981ed50f0273d9b43Status: Downloaded newer image for mysql:5.7

2.先查看本机都有哪些镜像,命令如下:

docker images
[root@localhost ~]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEmysql               5.7                 c73c7527c03a        8 days ago          412MBhello-world         latest              1815c82652c0        7 weeks ago         1.84kBjava                latest              d23bdf5b1b1b        6 months ago        643MBlearn/tutorial      latest              a7876479f1aa        4 years ago         128MB

3.然后启动我们的mysql的docker容器,命令如下:

docker run --name mysql5.7 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

注意,这里的容器名字叫:mysql5.7,mysql的root用户密码是:123456,映射宿主机子的端口3306到容器的端口3306,仓库名mysql和标签(tag)唯一确定了要指定的镜像,其实如果这里只有一个mysql也有必要要tag,执行该命令返回的结果是:

9238d9feb10a0c553d950451add144727b659a0972ccf04d7c59c3bfa198ed20

4.查看已经运行的的所有容器,命令如:docker ps

[root@localhost ~]# docker ps CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES9238d9feb10a        mysql:5.7           "docker-entrypoint..."   12 seconds ago      Up 9 seconds        0.0.0.0:3306->3306/tcp   mysql5.7[root@localhost ~]#

5.使用mysql的工具,比如navicat连接成功如下:
这里写图片描述

原创粉丝点击