【docker】【mysql】docker安装mysql,阿里云docker镜像加速器,docker搜索查看远程仓库上的镜像,docker拉取镜像,查看本地所有镜像,查看容器的运行状况,查看容器的详细信息

在docker上安装mysql有两种方式

1.通过Dockerfile构建

2.直接在docker hub上拉取镜像安装

=================本篇采用方法2=====================

1.搜索查找docker hub上的mysql镜像

docker search mysql

 

2.拉取官方镜像 标签为5.7,在此之前,先创建一个mysql目录,在目录中拉取

问题:在拉取过程中会出现龟速的问题

解决问题的方法:https://www.cnblogs.com/sxdcgaq8080/p/9198748.html

下载完成之后

 

3.下载完成之后,可以通过命令查看本地现有的所有镜像

docker images

 

也可以通过命令,通过Image ID查看具体某个镜像的详细信息

docker inspect 0d16d0a97dd1

 

4.运行docker镜像,即创建并实例化了一个容器

docker run -p 33060:3306 --name mysql4SXD -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=398023 -d mysql:5.7

命令说明:

  • -p 33060:3306:将容器的 3306 端口映射到主机的 33060 端口。

  • --name mysql4SXD : 给实例化本镜像生成的容器起个名字
  • -v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf。

  • -v $PWD/logs:/logs:将主机当前目录下的 logs 目录挂载到容器的 /logs。

  • -v $PWD/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql 。

  • -e MYSQL_ROOT_PASSWORD=398023:初始化 root 用户的密码。

  • -d mysql:5.7 : 后面跟的内容就是上面docker pull 拉取时候后面写的内容 ,本文上面的命令是:

    执行命令如下:

 

附录一个最简单的命令:

docker run -p 33061:3306 --name mysql --restart=always  -e MYSQL_ROOT_PASSWORD=jiayou -d mysql:5.7

启动一个叫mysql的docker实例,对外端口33061,设置的root密码是jiayou ,使用的镜像是 mysql:5.7  --restart=always表示无论容器的退出代码是什么,Docker都会自动重启该容器。

 

再附录一个启动时候处理了时区问题的命令:【具体的使用参考:https://www.cnblogs.com/sxdcgaq8080/p/10057385.html

docker run -p 33061:3306 --name mysql  --restart=always -e MYSQL_ROOT_PASSWORD=398023  -v /etc/localtime:/etc/localtime:ro  -v /etc/timezone:/etc/timezone:ro  -d mysql:5.7

额外的参数  更改了mysql时区的问题。

 

 

 

 

5.最后查看容器的运行状况

docker ps

 

 

6.也可以查看容器的详细信息

docker inspect 84a239a98f17
[root@localhost mysql-5.7]# docker inspect 84a239a98f17
[
    {
        "Id": "84a239a98f1775d6644c7dbe49f8bd5b007283988431911ff7c7175f0c39c5c8",
        "Created": "2018-06-19T08:45:12.811272153Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "mysqld"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 27162,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-06-19T08:45:13.123434469Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:0d16d0a97dd13a8ca0c0e205ce1f31f64d9d32048379eb322749442bff35f144",
        "ResolvConfPath": "/var/lib/docker/containers/84a239a98f1775d6644c7dbe49f8bd5b007283988431911ff7c7175f0c39c5c8/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/84a239a98f1775d6644c7dbe49f8bd5b007283988431911ff7c7175f0c39c5c8/hostname",
        "HostsPath": "/var/lib/docker/containers/84a239a98f1775d6644c7dbe49f8bd5b007283988431911ff7c7175f0c39c5c8/hosts",
        "LogPath": "/var/lib/docker/containers/84a239a98f1775d6644c7dbe49f8bd5b007283988431911ff7c7175f0c39c5c8/84a239a98f1775d6644c7dbe49f8bd5b007283988431911ff7c7175f0c39c5c8-json.log",
        "Name": "/mysql4SXD",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/apps/mysql-5.7/conf:/etc/mysql/conf.d",
                "/apps/mysql-5.7/logs:/logs",
                "/apps/mysql-5.7/data:/var/lib/mysql"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "3306/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "33060"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/30be23c185b7a236a2b22e66a5085537efc52232579a81147fd35e9a1a985a50-init/diff:/var/lib/docker/overlay2/69517a5927a811ce35906111fa25b5624edcc4e1a8ef8f0f142b4fc535685a88/diff:/var/lib/docker/overlay2/3ed3c6fb930bac0cb31b1b8fcc92b66e5557bad06ba0224dcb191c1c86e31d39/diff:/var/lib/docker/overlay2/828e767204392dd67f25ca076c77859c34559d638ef412cbc09579c56472444a/diff:/var/lib/docker/overlay2/20760b885e8c95781a63d5ad3c6a014275302b35726025c2377d3467a699abb0/diff:/var/lib/docker/overlay2/82665ac0867c090a438841853e35abf3eaafdd6d0aa23ad90c420da0e6867bbc/diff:/var/lib/docker/overlay2/5c48f19545216452ac99c428dfd913c80a1dd11388fa6777069d2706dc48a937/diff:/var/lib/docker/overlay2/94df4ac88cde8f504a4eb2d6a53c6a9a73c436dcaeeaf4fc9eb39a6f252263bc/diff:/var/lib/docker/overlay2/0bde00b0bfbf21da1d1d8999dad6d0e5029cd65ff1e02238cd097087a096573d/diff:/var/lib/docker/overlay2/4715e424689cc30667c39d411747c9a64ded56f450d1df733c454ddfc1230e0b/diff:/var/lib/docker/overlay2/77deb18f119a33c30795f60a15454f209ca2059bd329532f67eb8d07a97a5e51/diff:/var/lib/docker/overlay2/57e3c1d7be6569d6a1f52db172c973888855c1f4eac49c02fb07fc74639a2e0d/diff",
                "MergedDir": "/var/lib/docker/overlay2/30be23c185b7a236a2b22e66a5085537efc52232579a81147fd35e9a1a985a50/merged",
                "UpperDir": "/var/lib/docker/overlay2/30be23c185b7a236a2b22e66a5085537efc52232579a81147fd35e9a1a985a50/diff",
                "WorkDir": "/var/lib/docker/overlay2/30be23c185b7a236a2b22e66a5085537efc52232579a81147fd35e9a1a985a50/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/apps/mysql-5.7/conf",
                "Destination": "/etc/mysql/conf.d",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/apps/mysql-5.7/logs",
                "Destination": "/logs",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/apps/mysql-5.7/data",
                "Destination": "/var/lib/mysql",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "84a239a98f17",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "MYSQL_ROOT_PASSWORD=398023",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.7",
                "MYSQL_MAJOR=5.7",
                "MYSQL_VERSION=5.7.22-1debian9"
            ],
            "Cmd": [
                "mysqld"
            ],
            "ArgsEscaped": true,
            "Image": "mysql:5.7",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "9ad51b14aa486f96b3883fc9acff476387b94b833457e91147a6c77ebb3126a5",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3306/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "33060"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/9ad51b14aa48",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "65eee1d8d440722dc95e7eac27987bb2a627ea26ff00ecd3f042eec68b835724",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "4e2dc527d9ca0dbe2b7d8aacc5e24064c83f89bba6d3a72d78ae7fb4a48acd98",
                    "EndpointID": "65eee1d8d440722dc95e7eac27987bb2a627ea26ff00ecd3f042eec68b835724",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]
[root@localhost mysql-5.7]# 

 

 

7.查看mysql的运行日志

docker logs mysql4SXD

 

posted @ 2018-06-19 16:58  Angel挤一挤  阅读(6050)  评论(0编辑  收藏  举报