How to access a mysql database that is into a Docker continer?

I’m working in a windows environment and I have my MySQL database into a Docker container, but how I should access from an external application?

Right now I’m just want to use a regular Java Class to test the connection but what address should I use? I’ve tried with the boot2docker ip, but that doesn’t work. I’ve also tried with the ip that I got with the docker inspect command but I haven’t got any result.

  • Docker-compose run service if another service status is 0 (success)
  • Is there a way to “hibernate” a linux container
  • Downgrading from PHP 7 to PHP 5 on a Docker Server
  • `docker run` output to bash variable - strange behaviour
  • How do I link and scale multiple docker containers?
  • Django Logging Permission Error [Errno 13] Permission denied
  • [
    {
        "Id": "ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16",
        "Created": "2015-08-11T16:07:44.597618319Z",
        "Path": "/entrypoint.sh",
        "Args": [
            "mysqld"
        ],
        "State": {
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 2167,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2015-08-11T16:38:38.256276665Z",
            "FinishedAt": "2015-08-11T16:38:08.508576127Z"
        },
        "Image": "a128139aadf282a10ec937a60010f837fa1b91dd367e05c7ca6197a84b3115b3",
        "NetworkSettings": {
            "Bridge": "",
            "EndpointID": "a6e0a25891c065dc47b9dccb19c89e0ab7ee358a2b7cf947f6385bb47b99bac4",
            "Gateway": "172.17.42.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "HairpinMode": false,
            "IPAddress": "172.17.0.5",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "MacAddress": "02:42:ac:11:00:05",
            "NetworkID": "5c8e21999516c552412027ab316d3a8d8d813952fb207c1de9ec38040895fc50",
            "PortMapping": null,
            "Ports": {
                "3306/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/ee02d1e46305",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null
        },
        "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/resolv.conf",
        "HostnamePath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/hostname",
        "HostsPath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/hosts",
        "LogPath": "/mnt/sda1/var/lib/docker/containers/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16/ee02d1e463056c8dcd878fa7d9746c39b4377e051d11a8853be274b206b73c16-json.log",
        "Name": "/fluxtream",
        "RestartCount": 0,
        "Driver": "aufs",
        "ExecDriver": "native-0.2",
        "MountLabel": "",
        "ProcessLabel": "",
        "Volumes": {
            "/var/lib/mysql": "/mnt/sda1/var/lib/docker/volumes/5a05900d9551d22235e51a7d03a7354156fce1bdea3e7378f52df8d33fee1f4f/_data"
        },
        "VolumesRW": {
            "/var/lib/mysql": true
        },
        "AppArmorProfile": "",
        "ExecIDs": [
            "8fd70881d9cfed795dfb6850d513e54490432fd1e55e8bf8f6040f71cc1e7a4c",
            "d3ca3e35de0222127c7e5da3e6ab45157cb06f5716c0c2bbfdc9a7096230786d",
            "b75620585c02840a62169bc5adf0a5a80fa265194ac74136c54dc31cf9edd653",
            "a61e680448ad796b1ad113776c5ba46f3b8a03f6601d843b005722748c9d5669"
        ],
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LxcConf": [],
            "Memory": 0,
            "MemorySwap": 0,
            "CpuShares": 0,
            "CpuPeriod": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "CpuQuota": 0,
            "BlkioWeight": 0,
            "OomKillDisable": false,
            "Privileged": false,
            "PortBindings": {},
            "Links": null,
            "PublishAllPorts": false,
            "Dns": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "VolumesFrom": null,
            "Devices": [],
            "NetworkMode": "bridge",
            "IpcMode": "",
            "PidMode": "",
            "UTSMode": "",
            "CapAdd": null,
            "CapDrop": null,
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "SecurityOpt": null,
            "ReadonlyRootfs": false,
            "Ulimits": null,
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "CgroupParent": ""
        },
        "Config": {
            "Hostname": "ee02d1e46305",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "PortSpecs": null,
            "ExposedPorts": {
                "3306/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "MYSQL_ROOT_PASSWORD=fluxtream",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "MYSQL_MAJOR=5.6",
                "MYSQL_VERSION=5.6.26"
            ],
            "Cmd": [
                "mysqld"
            ],
            "Image": "mysql:5.6.26",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "VolumeDriver": "",
            "WorkingDir": "",
            "Entrypoint": [
                "/entrypoint.sh"
            ],
            "NetworkDisabled": false,
            "MacAddress": "",
            "OnBuild": null,
            "Labels": {}
        }
    }
    ]
    

    My dev enviroment:

    • Windows 7 Pro
    • Docker 1.7.0
    • Boot2Docker-cli version 1.7.0
    • MySQL container 5.6.26

  • cannot access Docker remote registry
  • Ubuntu nginx container 403 forbidden
  • How to know whether a layer exists locally on docker 1.10+
  • Docker - Jenkins Image
  • Docker capture packets
  • Docker compose ruby + postgres - cannot connect to postgres
  • One Solution collect form web for “How to access a mysql database that is into a Docker continer?”

    What worked for my is mapping the port when I created the container.

    docker run --name YOUR_CONTAINER -p 3306:3306 -e MYSQL_ROOT_PASSWORD=YOUR_PASS -d mysql:5.6.26
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.