无法连接到使用jdbc或mysql workbench作为docker容器安装的mysql示例

omtl5h9j  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(207)

我是docker的不速之客,刚刚安装了docker,并为mysql示例创建了一个容器。
docker run--name=mysql\u container-d-e mysql\u root\u password=root-e mysql\u root\u host=%-p 6603:6603 mysql/mysql服务器
能够使用docker exec访问mysql示例。
docker exec-it mysql\u容器mysql-uroot-p
无论如何,无法使用mysql工作台连接到docker mysql示例(本地机器中的mysql服务已关闭)。尝试了主机localhost和0.0.0.0,但仍然没有成功。
我刚刚运行了命令“docker inspect mysql_container”,响应如下:

[
{
    "Id": "12a30238bf11b08d9c029c528274db96175cc2edd976c8861e566e3ef4e26775",
    "Created": "2021-07-05T00:42:17.1792371Z",
    "Path": "/entrypoint.sh",
    "Args": [
        "mysqld"
    ],
    "State": {
        "Status": "running",
        "Running": true,
        "Paused": false,
        "Restarting": false,
        "OOMKilled": false,
        "Dead": false,
        "Pid": 1836,
        "ExitCode": 0,
        "Error": "",
        "StartedAt": "2021-07-05T00:42:17.567659Z",
        "FinishedAt": "0001-01-01T00:00:00Z",
        "Health": {
            "Status": "healthy",
            "FailingStreak": 0,
            "Log": [
                {
                    "Start": "2021-07-05T01:32:52.8156541Z",
                    "End": "2021-07-05T01:32:52.85896Z",
                    "ExitCode": 0,
                    "Output": "mysqld is alive\n"
                },
                {
                    "Start": "2021-07-05T01:33:22.8668644Z",
                    "End": "2021-07-05T01:33:22.9092576Z",
                    "ExitCode": 0,
                    "Output": "mysqld is alive\n"
                },
                {
                    "Start": "2021-07-05T01:33:52.9167436Z",
                    "End": "2021-07-05T01:33:52.9587054Z",
                    "ExitCode": 0,
                    "Output": "mysqld is alive\n"
                },
                {
                    "Start": "2021-07-05T01:34:22.9666096Z",
                    "End": "2021-07-05T01:34:23.0097958Z",
                    "ExitCode": 0,
                    "Output": "mysqld is alive\n"
                },
                {
                    "Start": "2021-07-05T01:34:53.0175935Z",
                    "End": "2021-07-05T01:34:53.0610566Z",
                    "ExitCode": 0,
                    "Output": "mysqld is alive\n"
                }
            ]
        }
    },
    "Image": "sha256:1504607f1ce72dde82fc3377dce506b347594baf0698ddb0b493977e6f07d739",
    "ResolvConfPath": "/var/lib/docker/containers/12a30238bf11b08d9c029c528274db96175cc2edd976c8861e566e3ef4e26775/resolv.conf",
    "HostnamePath": "/var/lib/docker/containers/12a30238bf11b08d9c029c528274db96175cc2edd976c8861e566e3ef4e26775/hostname",
    "HostsPath": "/var/lib/docker/containers/12a30238bf11b08d9c029c528274db96175cc2edd976c8861e566e3ef4e26775/hosts",
    "LogPath": "/var/lib/docker/containers/12a30238bf11b08d9c029c528274db96175cc2edd976c8861e566e3ef4e26775/12a30238bf11b08d9c029c528274db96175cc2edd976c8861e566e3ef4e26775-json.log",
    "Name": "/mysql_container",
    "RestartCount": 0,
    "Driver": "overlay2",
    "Platform": "linux",
    "MountLabel": "",
    "ProcessLabel": "",
    "AppArmorProfile": "",
    "ExecIDs": null,
    "HostConfig": {
        "Binds": null,
        "ContainerIDFile": "",
        "LogConfig": {
            "Type": "json-file",
            "Config": {}
        },
        "NetworkMode": "default",
        "PortBindings": {
            "6603/tcp": [
                {
                    "HostIp": "",
                    "HostPort": "6603"
                }
            ]
        },
        "RestartPolicy": {
            "Name": "no",
            "MaximumRetryCount": 0
        },
        "AutoRemove": false,
        "VolumeDriver": "",
        "VolumesFrom": null,
        "CapAdd": null,
        "CapDrop": null,
        "CgroupnsMode": "host",
        "Dns": [],
        "DnsOptions": [],
        "DnsSearch": [],
        "ExtraHosts": null,
        "GroupAdd": null,
        "IpcMode": "private",
        "Cgroup": "",
        "Links": null,
        "OomScoreAdj": 0,
        "PidMode": "",
        "Privileged": false,
        "PublishAllPorts": false,
        "ReadonlyRootfs": false,
        "SecurityOpt": null,
        "UTSMode": "",
        "UsernsMode": "",
        "ShmSize": 67108864,
        "Runtime": "runc",
        "ConsoleSize": [
            63,
            144
        ],
        "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,
        "DeviceRequests": null,
        "KernelMemory": 0,
        "KernelMemoryTCP": 0,
        "MemoryReservation": 0,
        "MemorySwap": 0,
        "MemorySwappiness": null,
        "OomKillDisable": false,
        "PidsLimit": null,
        "Ulimits": null,
        "CpuCount": 0,
        "CpuPercent": 0,
        "IOMaximumIOps": 0,
        "IOMaximumBandwidth": 0,
        "MaskedPaths": [
            "/proc/asound",
            "/proc/acpi",
            "/proc/kcore",
            "/proc/keys",
            "/proc/latency_stats",
            "/proc/timer_list",
            "/proc/timer_stats",
            "/proc/sched_debug",
            "/proc/scsi",
            "/sys/firmware"
        ],
        "ReadonlyPaths": [
            "/proc/bus",
            "/proc/fs",
            "/proc/irq",
            "/proc/sys",
            "/proc/sysrq-trigger"
        ]
    },
    "GraphDriver": {
        "Data": {
            "LowerDir": "/var/lib/docker/overlay2/03a28621f28b92827eaf38f097b25ba53ab31091c3554e0600b721e09c9beb1f-init/diff:/var/lib/docker/overlay2/f43a2ac50d2b3b388b1947fa3a44859c932394c977df5d06e8947eabb13fe154/diff:/var/lib/docker/overlay2/f4fbbff8a89d0bd37b24fcdc05c87bb8d5b322a2cfb756a8bc776c22bef0ba0f/diff:/var/lib/docker/overlay2/47159eeeb0fbd80023fd2ca0e4137766720705180a51fe91dc451fb633cb53ab/diff:/var/lib/docker/overlay2/a7417372516cb1940f18eee241a818b1848e5ff42742fbd77d4df90fd6bd0bcf/diff:/var/lib/docker/overlay2/da77a65d253059537efe311f21e4ce98f70aca276e3e0ecf57757951d77ce0f3/diff:/var/lib/docker/overlay2/8f2a3f629a3bf570743b74f0d9a4211f0666bec21236d4dbd3aa4f6bdbd70743/diff:/var/lib/docker/overlay2/83115d68cd30bf8f45d038c01136c983d94e4d1499ec05a720c2c63aaa0a82a8/diff",
            "MergedDir": "/var/lib/docker/overlay2/03a28621f28b92827eaf38f097b25ba53ab31091c3554e0600b721e09c9beb1f/merged",
            "UpperDir": "/var/lib/docker/overlay2/03a28621f28b92827eaf38f097b25ba53ab31091c3554e0600b721e09c9beb1f/diff",
            "WorkDir": "/var/lib/docker/overlay2/03a28621f28b92827eaf38f097b25ba53ab31091c3554e0600b721e09c9beb1f/work"
        },
        "Name": "overlay2"
    },
    "Mounts": [],
    "Config": {
        "Hostname": "12a30238bf11",
        "Domainname": "",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "ExposedPorts": {
            "3306/tcp": {},
            "33060/tcp": {},
            "33061/tcp": {},
            "6603/tcp": {}
        },
        "Tty": false,
        "OpenStdin": false,
        "StdinOnce": false,
        "Env": [
            "MYSQL_ROOT_PASSWORD=root",
            "MYSQL_ROOT_HOST=%",
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock"
        ],
        "Cmd": [
            "mysqld"
        ],
        "Healthcheck": {
            "Test": [
                "CMD-SHELL",
                "/healthcheck.sh"
            ]
        },
        "Image": "mysql/mysql-server",
        "Volumes": null,
        "WorkingDir": "",
        "Entrypoint": [
            "/entrypoint.sh"
        ],
        "OnBuild": null,
        "Labels": {}
    },
    "NetworkSettings": {
        "Bridge": "",
        "SandboxID": "7c248259a881c317cc21697199a87a7f4706c4a07f0f91c39632194318eab418",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "3306/tcp": null,
            "33060/tcp": null,
            "33061/tcp": null,
            "6603/tcp": [
                {
                    "HostIp": "0.0.0.0",
                    "HostPort": "6603"
                },
                {
                    "HostIp": "::",
                    "HostPort": "6603"
                }
            ]
        },
        "SandboxKey": "/var/run/docker/netns/7c248259a881",
        "SecondaryIPAddresses": null,
        "SecondaryIPv6Addresses": null,
        "EndpointID": "f6ac3760c826e052b525292499ee166608f8307f4cd8618022bfdd8600cdfa54",
        "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": "15d5f77b059c4a53a1182f61dd8cf54734e63e79058cd12d04a2e54867302a37",
                "EndpointID": "f6ac3760c826e052b525292499ee166608f8307f4cd8618022bfdd8600cdfa54",
                "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
            }
        }
    }
}

]
spring启动应用程序的application.properties如下


# spring.datasource.url=jdbc:mysql://localhost:6603/test

# spring.datasource.url=jdbc:mysql://0.0.0.0:6603/test

spring.datasource.url=jdbc:mysql://172.17.0.2:6603/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题