停靠Java应用程序连接无法停靠mysql数据库

gkn4icbw  于 2022-11-28  发布在  Mysql
关注(0)|答案(1)|浏览(143)

我试图连接我的java应用程序到我的mysql容器,但失败的连接发生。
当我在本地运行我的应用程序时,一切都正常工作,Java应用程序和MySQL容器之间的连接建立起来了。
但我试图停靠我的java应用程序,它不工作。
下面是我运行mysql容器的方法:

version: '2'
services:
  mysql:
    image: mysql:latest
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=$DB_ROOT_PWD
      - MYSQL_DATABASE=$DB_NAME
      - MYSQL_USER=$DB_USER
      - MYSQL_PASSWORD=$DB_PWD
    volumes:
      - msql-data:/var/lib/msql
volumes:
  msql-data:
    driver: local

下面是我的java应用程序的配置

@Configuration
public class DatabaseConfig {

    private String user = System.getenv("DB_USER");
    private String password = System.getenv("DB_PWD");
    private String serverName = System.getenv("DB_SERVER"); // db host name, like localhost without the port
    private String dbName = System.getenv("DB_NAME");
    private MysqlDataSource datasource = new MysqlDataSource();

    public DatabaseConfig() {
        datasource.setPassword(password);
        datasource.setUser(user);
        datasource.setServerName(serverName);
        datasource.setDatabaseName(dbName);
        //datasource.setPort(3306) default config
        //datasource.setURL("jdbc:mysql://localhost:3306/dbname");

    }

这是我的dockerfile

FROM openjdk:8-jdk-alpine

ENV DB_USER=$user \
    DB_NAME=$db_name \
    DB_SERVER=$server_location \
    DB_PWD=$user_pwd

RUN mkdir -p /app/

COPY java_app.jar /app/app.jar

EXPOSE 8080

CMD ["java","-jar","/app/app.jar"]

启动停靠文件的命令

docker build -t my-app:1.0 --build-arg user=$DB_USER --build-arg db_name=$DB_NAME --build-arg server_location=$DB_SERVER --build-arg user_pwd=$DB_PWD .

启动应用程序的命令

docker run --name=app -tid app:1

结果:Result

cyvaqqii

cyvaqqii1#

下面是我的mysql容器的描述:

[
    {
        "Id": "c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a",
        "Created": "2022-11-15T16:28:37.7824683Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "mysqld"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 3612,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-11-22T08:43:02.516250834Z",
            "FinishedAt": "2022-11-15T16:40:41.756218474Z"
        },
        "Image": "sha256:c2c2eba5ae857a8ab9bffd11c5f15ed693dc65ac035948696f370f2895ae3062",
        "ResolvConfPath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/hostname",
        "HostsPath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/hosts",
        "LogPath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a-json.log",
        "Name": "/mysql",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "mysql_volume:/var/lib/mysql"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "mysql_network",
            "PortBindings": {
                "3306/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "3306"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "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": [
                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,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "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/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7-init/diff:/var/lib/docker/overlay2/d8ca08d39816b678f4ff69240c90229b23c46c5086bb77ffa7b88c7f5464735c/diff:/var/lib/docker/overlay2/e2159f6af08f6d0214d13f78affae06e5da6fff0d8c71b98413324a66042b25f/diff:/var/lib/docker/overlay2/92e192a736981a3acfe98d22358377a26e825a15cf3d82198388353c815e87be/diff:/var/lib/docker/overlay2/ea14f5147698df121ddf70c16c1cf3d493b7c31333445feaa0008e354e718d8d/diff:/var/lib/docker/overlay2/81d65959518757a914d4ce3751a1d066ac3a56be805cd4a047a6e60a56e20e8e/diff:/var/lib/docker/overlay2/5f735bca3d6dfb1f8f285603f8846bbc519640535856f55fe79252112a76bded/diff:/var/lib/docker/overlay2/662d188a66c334f02b09ec597dacb03d5ceacb4c5e921d2bd8acfe0832860136/diff:/var/lib/docker/overlay2/384a61911d618a2967fd48238053b8065a225ce8f0019284d2249995c80581bb/diff:/var/lib/docker/overlay2/d41c1f867589aa3a04b9214b2643ea110a558036d35fe04deeed08edd8907030/diff:/var/lib/docker/overlay2/1ff2c1ca637584758052f92175af56775cdb75f2d07a73d0ced3c767ca86b718/diff:/var/lib/docker/overlay2/c6233db4fc7c2c7710937c8940ad021bc1815a7ac9f4fa26ed806424721e17ed/diff",
                "MergedDir": "/var/lib/docker/overlay2/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7/merged",
                "UpperDir": "/var/lib/docker/overlay2/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7/diff",
                "WorkDir": "/var/lib/docker/overlay2/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "mysql_volume",
                "Source": "/var/lib/docker/volumes/mysql_volume/_data",
                "Destination": "/var/lib/mysql",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "c74d11722ea8",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {},
                "33060/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "MYSQL_DATABASE=db_java_app",
                "MYSQL_USER=john",
                "MYSQL_PASSWORD=john123",
                "MYSQL_ROOT_PASSWORD=root123",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.14",
                "MYSQL_MAJOR=8.0",
                "MYSQL_VERSION=8.0.31-1.el8",
                "MYSQL_SHELL_VERSION=8.0.31-1.el8"
            ],
            "Cmd": [
                "mysqld"
            ],
            "Image": "mysql:latest",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "babc7bf952f7385392bcd991264f04c64e589a4a8fcf8283248ad9693f00c517",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3306/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "3306"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "3306"
                    }
                ],
                "33060/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/babc7bf952f7",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "mysql_network": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "c74d11722ea8"
                    ],
                    "NetworkID": "1c55f0de4328659514ef4bc8cba19895edb9215792e98ffed1e38a8774c25ce3",
                    "EndpointID": "4826f73d6db1a36e5b50e6bb68bffb1d6fb3dccd4611b2c78b53bf4f7d8e5296",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]



[
    {
        "Id": "c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a",
        "Created": "2022-11-15T16:28:37.7824683Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "mysqld"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 3612,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-11-22T08:43:02.516250834Z",
            "FinishedAt": "2022-11-15T16:40:41.756218474Z"
        },
        "Image": "sha256:c2c2eba5ae857a8ab9bffd11c5f15ed693dc65ac035948696f370f2895ae3062",
        "ResolvConfPath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/hostname",
        "HostsPath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/hosts",
        "LogPath": "/var/lib/docker/containers/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a/c74d11722ea806f46266ca50450f98fffde01fffdab446df9a09cd6539c6465a-json.log",
        "Name": "/mysql",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "mysql_volume:/var/lib/mysql"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "mysql_network",
            "PortBindings": {
                "3306/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "3306"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "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": [
                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,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "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/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7-init/diff:/var/lib/docker/overlay2/d8ca08d39816b678f4ff69240c90229b23c46c5086bb77ffa7b88c7f5464735c/diff:/var/lib/docker/overlay2/e2159f6af08f6d0214d13f78affae06e5da6fff0d8c71b98413324a66042b25f/diff:/var/lib/docker/overlay2/92e192a736981a3acfe98d22358377a26e825a15cf3d82198388353c815e87be/diff:/var/lib/docker/overlay2/ea14f5147698df121ddf70c16c1cf3d493b7c31333445feaa0008e354e718d8d/diff:/var/lib/docker/overlay2/81d65959518757a914d4ce3751a1d066ac3a56be805cd4a047a6e60a56e20e8e/diff:/var/lib/docker/overlay2/5f735bca3d6dfb1f8f285603f8846bbc519640535856f55fe79252112a76bded/diff:/var/lib/docker/overlay2/662d188a66c334f02b09ec597dacb03d5ceacb4c5e921d2bd8acfe0832860136/diff:/var/lib/docker/overlay2/384a61911d618a2967fd48238053b8065a225ce8f0019284d2249995c80581bb/diff:/var/lib/docker/overlay2/d41c1f867589aa3a04b9214b2643ea110a558036d35fe04deeed08edd8907030/diff:/var/lib/docker/overlay2/1ff2c1ca637584758052f92175af56775cdb75f2d07a73d0ced3c767ca86b718/diff:/var/lib/docker/overlay2/c6233db4fc7c2c7710937c8940ad021bc1815a7ac9f4fa26ed806424721e17ed/diff",
                "MergedDir": "/var/lib/docker/overlay2/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7/merged",
                "UpperDir": "/var/lib/docker/overlay2/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7/diff",
                "WorkDir": "/var/lib/docker/overlay2/86c0c59c63d20f7dd32ba6097c315a7032595ecc3de2fea4514e8345b99eb1b7/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "mysql_volume",
                "Source": "/var/lib/docker/volumes/mysql_volume/_data",
                "Destination": "/var/lib/mysql",
                "Driver": "local",
                "Mode": "z",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "c74d11722ea8",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {},
                "33060/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "MYSQL_DATABASE=db_java_app",
                "MYSQL_USER=john",
                "MYSQL_PASSWORD=john123",
                "MYSQL_ROOT_PASSWORD=root123",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.14",
                "MYSQL_MAJOR=8.0",
                "MYSQL_VERSION=8.0.31-1.el8",
                "MYSQL_SHELL_VERSION=8.0.31-1.el8"
            ],
            "Cmd": [
                "mysqld"
            ],
            "Image": "mysql:latest",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "babc7bf952f7385392bcd991264f04c64e589a4a8fcf8283248ad9693f00c517",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3306/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "3306"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "3306"
                    }
                ],
                "33060/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/babc7bf952f7",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "mysql_network": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "c74d11722ea8"
                    ],
                    "NetworkID": "1c55f0de4328659514ef4bc8cba19895edb9215792e98ffed1e38a8774c25ce3",
                    "EndpointID": "4826f73d6db1a36e5b50e6bb68bffb1d6fb3dccd4611b2c78b53bf4f7d8e5296",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

下面是我的Java APP容器的描述:

[
    {
        "Id": "46b942e964dfa98747377b092e6c8ac694960e894bfcc180fc151055ab505057",
        "Created": "2022-11-22T08:50:55.370286221Z",
        "Path": "java",
        "Args": [
            "-jar",
            "/app/app.jar"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 1,
            "Error": "",
            "StartedAt": "2022-11-22T08:50:55.982290829Z",
            "FinishedAt": "2022-11-22T08:51:00.890786446Z"
        },
        "Image": "sha256:e3f03d1f45d29cdeadf2aca318ce54a10bfde51b53cadfb875cb6dc7a0de0d6e",
        "ResolvConfPath": "/var/lib/docker/containers/46b942e964dfa98747377b092e6c8ac694960e894bfcc180fc151055ab505057/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/46b942e964dfa98747377b092e6c8ac694960e894bfcc180fc151055ab505057/hostname",
        "HostsPath": "/var/lib/docker/containers/46b942e964dfa98747377b092e6c8ac694960e894bfcc180fc151055ab505057/hosts",
        "LogPath": "/var/lib/docker/containers/46b942e964dfa98747377b092e6c8ac694960e894bfcc180fc151055ab505057/46b942e964dfa98747377b092e6c8ac694960e894bfcc180fc151055ab505057-json.log",
        "Name": "/myapp",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "mysql_network",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "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": [
                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,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "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/2c0b7aa4ae063988eeb2e272fdf5e0f5c7d4f96a3847b0e082a046bdd3fbe343-init/diff:/var/lib/docker/overlay2/d6ea632eafd6345bc059412ec2d96ed811ead1f3e998237d7263855bb053efaf/diff:/var/lib/docker/overlay2/c146ff42f8a1665afdebb048d00b335e73efce80bbdb83bde82c3525a8ade646/diff:/var/lib/docker/overlay2/c5554145ca0e3f36429be44390378bacab32dc8576a2d2a64293de82e797be0e/diff:/var/lib/docker/overlay2/4219b18337703078b79e874b5c1c8d8ed39e8cdd9838908af8f7a7840c35b6e8/diff:/var/lib/docker/overlay2/128954eb39191a6bb5bbf8ceca9d7dae987d856a2f604fb461a40c9574e69bf8/diff",
                "MergedDir": "/var/lib/docker/overlay2/2c0b7aa4ae063988eeb2e272fdf5e0f5c7d4f96a3847b0e082a046bdd3fbe343/merged",
                "UpperDir": "/var/lib/docker/overlay2/2c0b7aa4ae063988eeb2e272fdf5e0f5c7d4f96a3847b0e082a046bdd3fbe343/diff",
                "WorkDir": "/var/lib/docker/overlay2/2c0b7aa4ae063988eeb2e272fdf5e0f5c7d4f96a3847b0e082a046bdd3fbe343/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "46b942e964df",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "ExposedPorts": {
                "3306/tcp": {},
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk",
                "JAVA_VERSION=8u212",
                "JAVA_ALPINE_VERSION=8.212.04-r0",
                "DB_USER=john",
                "DB_NAME=db_java_app",
                "DB_SERVER=localhost",
                "DB_PWD=john123"
            ],
            "Cmd": [
                "java",
                "-jar",
                "/app/app.jar"
            ],
            "Image": "app:1",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "7843d4db94ece03110081f5f4432fdd14d3fa1547159577972fe8e9b5288c4e5",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/7843d4db94ec",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "mysql_network": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "46b942e964df"
                    ],
                    "NetworkID": "1c55f0de4328659514ef4bc8cba19895edb9215792e98ffed1e38a8774c25ce3",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]
  • 当我从应用程序容器ping mysql时,它工作
  • 当我从应用程序容器telnet mysql 3306时,我得到了这个:
J
8.0.31:8a/}lVs�FNN#gXlcaching_sha2_password

相关问题