【docker】【mysql】docker安裝mysql,阿里雲docker鏡像加速器,docker搜索查看遠程倉庫上的鏡像,docker拉取鏡像,查看本地全部鏡像,查看容器的運行情況,查看容器的詳細

在docker上安裝mysql有兩種方式html

1.經過Dockerfile構建mysql

2.直接在docker hub上拉取鏡像安裝linux

=================本篇採用方法2=====================sql

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

docker search mysql

 

2.拉取官方鏡像 標籤爲5.7,在此以前,先建立一個mysql目錄,在目錄中拉取json

問題:在拉取過程當中會出現龜速的問題app

解決問題的方法:http://www.javashuo.com/article/p-pwpzblpz-gb.htmltcp

下載完成以後ui

 

3.下載完成以後,能夠經過命令查看本地現有的全部鏡像spa

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都會自動重啓該容器。

 

再附錄一個啓動時候處理了時區問題的命令:【具體的使用參考:http://www.javashuo.com/article/p-orubytkd-ba.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

相關文章
相關標籤/搜索