<p>I'm running Jenkins which runs a container in a pod which runs a maven build.</p>
<p>In the build, a test spins up a <a href="https://hub.docker.com/layers/mysql/library/mysql/5.7.31/images/sha256-a175aaebe819a4f0beb626ae99ff771ab885a44f2ba9c104a58ff6665d73e33f?context=explore" rel="nofollow noreferrer"><code>mysql</code></a> container and gets a 'connection refused'. Locally, outside of Jenkins, it works fine.</p>
<p>The container is run via:</p>
<pre class="lang-sh prettyprint-override"><code>docker run --name mysql_unit_test -e MYSQL_ROOT_PASSWORD=abcd1234! -e MYSQL_DATABASE=db -p 4306:3306 -d mysql:5.7.13
</code></pre>
<p><code>docker ps</code> produces:</p>
<pre class="lang-sh prettyprint-override"><code>816a19116f2d  mysql:5.7.13  &quot;docker-entrypoint.s…&quot;  17 hours ago  Up 17 hours  0.0.0.0:4306-&gt;3306/tcp  mysql_unit_test
</code></pre>
<p>And <code>docker inspect</code>:</p>
<pre><code>[
    {
        &quot;Id&quot;: &quot;816a19116f2dd947013baa2abe5555317afec448fa8f56258fce4dce53f33a09&quot;,
        &quot;Created&quot;: &quot;2020-07-22T04:43:36.556743179Z&quot;,
        &quot;Path&quot;: &quot;docker-entrypoint.sh&quot;,
        &quot;Args&quot;: [
            &quot;mysqld&quot;
        ],
        &quot;State&quot;: {
            &quot;Status&quot;: &quot;running&quot;,
            &quot;Running&quot;: true,
            &quot;Paused&quot;: false,
            &quot;Restarting&quot;: false,
            &quot;OOMKilled&quot;: false,
            &quot;Dead&quot;: false,
            &quot;Pid&quot;: 84461,
            &quot;ExitCode&quot;: 0,
            &quot;Error&quot;: &quot;&quot;,
            &quot;StartedAt&quot;: &quot;2020-07-22T04:43:37.219671572Z&quot;,
            &quot;FinishedAt&quot;: &quot;0001-01-01T00:00:00Z&quot;
        },
        &quot;Image&quot;: &quot;sha256:1195b21c3a45d9bf93aae497f2538f89a09aaded18d6648753aa3ce76670f41d&quot;,
        &quot;ResolvConfPath&quot;: &quot;/var/lib/docker/containers/816a19116f2dd947013baa2abe5555317afec448fa8f56258fce4dce53f33a09/resolv.conf&quot;,
        &quot;HostnamePath&quot;: &quot;/var/lib/docker/containers/816a19116f2dd947013baa2abe5555317afec448fa8f56258fce4dce53f33a09/hostname&quot;,
        &quot;HostsPath&quot;: &quot;/var/lib/docker/containers/816a19116f2dd947013baa2abe5555317afec448fa8f56258fce4dce53f33a09/hosts&quot;,
        &quot;LogPath&quot;: &quot;/var/lib/docker/containers/816a19116f2dd947013baa2abe5555317afec448fa8f56258fce4dce53f33a09/816a19116f2dd947013baa2abe5555317afec448fa8f56258fce4dce53f33a09-json.log&quot;,
        &quot;Name&quot;: &quot;/mysql_unit_test&quot;,
        &quot;RestartCount&quot;: 0,
        &quot;Driver&quot;: &quot;overlay2&quot;,
        &quot;Platform&quot;: &quot;linux&quot;,
        &quot;MountLabel&quot;: &quot;&quot;,
        &quot;ProcessLabel&quot;: &quot;&quot;,
        &quot;AppArmorProfile&quot;: &quot;docker-default&quot;,
        &quot;ExecIDs&quot;: null,
        &quot;HostConfig&quot;: {
            &quot;Binds&quot;: null,
            &quot;ContainerIDFile&quot;: &quot;&quot;,
            &quot;LogConfig&quot;: {
                &quot;Type&quot;: &quot;json-file&quot;,
                &quot;Config&quot;: {
                    &quot;max-file&quot;: &quot;5&quot;,
                    &quot;max-size&quot;: &quot;50m&quot;
                }
            },
            &quot;NetworkMode&quot;: &quot;default&quot;,
            &quot;PortBindings&quot;: {
                &quot;3306/tcp&quot;: [
                    {
                        &quot;HostIp&quot;: &quot;&quot;,
                        &quot;HostPort&quot;: &quot;4306&quot;
                    }
                ]
            },
            &quot;RestartPolicy&quot;: {
                &quot;Name&quot;: &quot;no&quot;,
                &quot;MaximumRetryCount&quot;: 0
            },
            &quot;AutoRemove&quot;: false,
            &quot;VolumeDriver&quot;: &quot;&quot;,
            &quot;VolumesFrom&quot;: null,
            &quot;CapAdd&quot;: null,
            &quot;CapDrop&quot;: null,
            &quot;Capabilities&quot;: null,
            &quot;Dns&quot;: [],
            &quot;DnsOptions&quot;: [],
            &quot;DnsSearch&quot;: [],
            &quot;ExtraHosts&quot;: null,
            &quot;GroupAdd&quot;: null,
            &quot;IpcMode&quot;: &quot;private&quot;,
            &quot;Cgroup&quot;: &quot;&quot;,
            &quot;Links&quot;: null,
            &quot;OomScoreAdj&quot;: 0,
            &quot;PidMode&quot;: &quot;&quot;,
            &quot;Privileged&quot;: false,
            &quot;PublishAllPorts&quot;: false,
            &quot;ReadonlyRootfs&quot;: false,
            &quot;SecurityOpt&quot;: null,
            &quot;UTSMode&quot;: &quot;&quot;,
            &quot;UsernsMode&quot;: &quot;&quot;,
            &quot;ShmSize&quot;: 67108864,
            &quot;Runtime&quot;: &quot;runc&quot;,
            &quot;ConsoleSize&quot;: [
                0,
                0
            ],
            &quot;Isolation&quot;: &quot;&quot;,
            &quot;CpuShares&quot;: 0,
            &quot;Memory&quot;: 0,
            &quot;NanoCpus&quot;: 0,
            &quot;CgroupParent&quot;: &quot;&quot;,
            &quot;BlkioWeight&quot;: 0,
            &quot;BlkioWeightDevice&quot;: [],
            &quot;BlkioDeviceReadBps&quot;: null,
            &quot;BlkioDeviceWriteBps&quot;: null,
            &quot;BlkioDeviceReadIOps&quot;: null,
            &quot;BlkioDeviceWriteIOps&quot;: null,
            &quot;CpuPeriod&quot;: 0,
            &quot;CpuQuota&quot;: 0,
            &quot;CpuRealtimePeriod&quot;: 0,
            &quot;CpuRealtimeRuntime&quot;: 0,
            &quot;CpusetCpus&quot;: &quot;&quot;,
            &quot;CpusetMems&quot;: &quot;&quot;,
            &quot;Devices&quot;: [],
            &quot;DeviceCgroupRules&quot;: null,
            &quot;DeviceRequests&quot;: null,
            &quot;KernelMemory&quot;: 0,
            &quot;KernelMemoryTCP&quot;: 0,
            &quot;MemoryReservation&quot;: 0,
            &quot;MemorySwap&quot;: 0,
            &quot;MemorySwappiness&quot;: null,
            &quot;OomKillDisable&quot;: false,
            &quot;PidsLimit&quot;: null,
            &quot;Ulimits&quot;: null,
            &quot;CpuCount&quot;: 0,
            &quot;CpuPercent&quot;: 0,
            &quot;IOMaximumIOps&quot;: 0,
            &quot;IOMaximumBandwidth&quot;: 0,
            &quot;MaskedPaths&quot;: [
                &quot;/proc/asound&quot;,
                &quot;/proc/acpi&quot;,
                &quot;/proc/kcore&quot;,
                &quot;/proc/keys&quot;,
                &quot;/proc/latency_stats&quot;,
                &quot;/proc/timer_list&quot;,
                &quot;/proc/timer_stats&quot;,
                &quot;/proc/sched_debug&quot;,
                &quot;/proc/scsi&quot;,
                &quot;/sys/firmware&quot;
            ],
            &quot;ReadonlyPaths&quot;: [
                &quot;/proc/bus&quot;,
                &quot;/proc/fs&quot;,
                &quot;/proc/irq&quot;,
                &quot;/proc/sys&quot;,
                &quot;/proc/sysrq-trigger&quot;
            ]
        },
        &quot;GraphDriver&quot;: {
            &quot;Data&quot;: {
                &quot;LowerDir&quot;: &quot;/var/lib/docker/overlay2/ccba4cc84fd186833c2bb0a6976a356bf1167cc834b06f4165984367b8ca69ef-init/diff:/var/lib/docker/overlay2/cf95f3dcd155ff4d3723bb3283e50af755a9a48c1febef3b1889ace131b9242d/diff:/var/lib/docker/overlay2/58a035059ace166a43c538e8bd48d80ad80af4bf5c43a3ff1da6b31490fd6380/diff:/var/lib/docker/overlay2/045b842ce5119b1ec1aa1da2e93a54d69df9d16cdbc531746089a4e881bff44a/diff:/var/lib/docker/overlay2/ed9de3c8ec5891ee8619e4cca70ea041b112650b3fce543840e25ce5acf038f7/diff:/var/lib/docker/overlay2/cf3af22c1d68cd4b42f97896d5b55f9433972354f67b48499fce6fd7a9c8b2da/diff:/var/lib/docker/overlay2/079d799ee0d806d8428533c7ca65347bc579d795e47b5fb8d9f0491d11658261/diff:/var/lib/docker/overlay2/ba3cd6723b68d9cde09712cad0dd6f6a3cd3989e5f69872a35d60ea5ab76a12d/diff:/var/lib/docker/overlay2/0c9c8a78c4f329888e1fb40aba0fc688f1090c84a6823aa443d08445f2c9ba5f/diff:/var/lib/docker/overlay2/12cac8cdd33fabd38487d14a1599516f14bd79421f5a9a04cf926ca8d2c5bc0f/diff:/var/lib/docker/overlay2/f844165a3a8f81c0d5703f0e27b6cb3ace6c6559b256f1b4dcf91158e0f5a384/diff:/var/lib/docker/overlay2/34c41e90c5210a0aec026543d85d5c17e01287a087607b79c74db82ebff94ee5/diff&quot;,
                &quot;MergedDir&quot;: &quot;/var/lib/docker/overlay2/ccba4cc84fd186833c2bb0a6976a356bf1167cc834b06f4165984367b8ca69ef/merged&quot;,
                &quot;UpperDir&quot;: &quot;/var/lib/docker/overlay2/ccba4cc84fd186833c2bb0a6976a356bf1167cc834b06f4165984367b8ca69ef/diff&quot;,
                &quot;WorkDir&quot;: &quot;/var/lib/docker/overlay2/ccba4cc84fd186833c2bb0a6976a356bf1167cc834b06f4165984367b8ca69ef/work&quot;
            },
            &quot;Name&quot;: &quot;overlay2&quot;
        },
        &quot;Mounts&quot;: [
            {
                &quot;Type&quot;: &quot;volume&quot;,
                &quot;Name&quot;: &quot;571074f25fbd2d154dcf2b563af0a3fd42c1d5987c561f4fb23ba37c785a49d1&quot;,
                &quot;Source&quot;: &quot;/var/lib/docker/volumes/571074f25fbd2d154dcf2b563af0a3fd42c1d5987c561f4fb23ba37c785a49d1/_data&quot;,
                &quot;Destination&quot;: &quot;/var/lib/mysql&quot;,
                &quot;Driver&quot;: &quot;local&quot;,
                &quot;Mode&quot;: &quot;&quot;,
                &quot;RW&quot;: true,
                &quot;Propagation&quot;: &quot;&quot;
            }
        ],
        &quot;Config&quot;: {
            &quot;Hostname&quot;: &quot;816a19116f2d&quot;,
            &quot;Domainname&quot;: &quot;&quot;,
            &quot;User&quot;: &quot;&quot;,
            &quot;AttachStdin&quot;: false,
            &quot;AttachStdout&quot;: false,
            &quot;AttachStderr&quot;: false,
            &quot;ExposedPorts&quot;: {
                &quot;3306/tcp&quot;: {}
            },
            &quot;Tty&quot;: false,
            &quot;OpenStdin&quot;: false,
            &quot;StdinOnce&quot;: false,
            &quot;Env&quot;: [
                &quot;MYSQL_ROOT_PASSWORD=abcd1234!&quot;,
                &quot;MYSQL_DATABASE=db&quot;,
                &quot;PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin&quot;,
                &quot;GOSU_VERSION=1.7&quot;,
                &quot;MYSQL_MAJOR=5.7&quot;,
                &quot;MYSQL_VERSION=5.7.13-1debian8&quot;
            ],
            &quot;Cmd&quot;: [
                &quot;mysqld&quot;
            ],
            &quot;Image&quot;: &quot;mysql:5.7.13&quot;,
            &quot;Volumes&quot;: {
                &quot;/var/lib/mysql&quot;: {}
            },
            &quot;WorkingDir&quot;: &quot;&quot;,
            &quot;Entrypoint&quot;: [
                &quot;docker-entrypoint.sh&quot;
            ],
            &quot;OnBuild&quot;: null,
            &quot;Labels&quot;: {}
        },
        &quot;NetworkSettings&quot;: {
            &quot;Bridge&quot;: &quot;&quot;,
            &quot;SandboxID&quot;: &quot;99fb1d64dbd98500d7dddae88ea2b53e712da9a709f8541fcae413f52d18a309&quot;,
            &quot;HairpinMode&quot;: false,
            &quot;LinkLocalIPv6Address&quot;: &quot;&quot;,
            &quot;LinkLocalIPv6PrefixLen&quot;: 0,
            &quot;Ports&quot;: {
                &quot;3306/tcp&quot;: [
                    {
                        &quot;HostIp&quot;: &quot;0.0.0.0&quot;,
                        &quot;HostPort&quot;: &quot;4306&quot;
                    }
                ]
            },
            &quot;SandboxKey&quot;: &quot;/var/run/docker/netns/99fb1d64dbd9&quot;,
            &quot;SecondaryIPAddresses&quot;: null,
            &quot;SecondaryIPv6Addresses&quot;: null,
            &quot;EndpointID&quot;: &quot;375f5604e67cd5282d09585e2b211df7d8c1482b448f95003b38eaf5755c3982&quot;,
            &quot;Gateway&quot;: &quot;172.17.0.1&quot;,
            &quot;GlobalIPv6Address&quot;: &quot;&quot;,
            &quot;GlobalIPv6PrefixLen&quot;: 0,
            &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,
            &quot;IPPrefixLen&quot;: 16,
            &quot;IPv6Gateway&quot;: &quot;&quot;,
            &quot;MacAddress&quot;: &quot;02:42:ac:11:00:02&quot;,
            &quot;Networks&quot;: {
                &quot;bridge&quot;: {
                    &quot;IPAMConfig&quot;: null,
                    &quot;Links&quot;: null,
                    &quot;Aliases&quot;: null,
                    &quot;NetworkID&quot;: &quot;526388f448225716c3159ae806600b8507086e898f41d3945d24d8c4572e3848&quot;,
                    &quot;EndpointID&quot;: &quot;375f5604e67cd5282d09585e2b211df7d8c1482b448f95003b38eaf5755c3982&quot;,
                    &quot;Gateway&quot;: &quot;172.17.0.1&quot;,
                    &quot;IPAddress&quot;: &quot;172.17.0.2&quot;,
                    &quot;IPPrefixLen&quot;: 16,
                    &quot;IPv6Gateway&quot;: &quot;&quot;,
                    &quot;GlobalIPv6Address&quot;: &quot;&quot;,
                    &quot;GlobalIPv6PrefixLen&quot;: 0,
                    &quot;MacAddress&quot;: &quot;02:42:ac:11:00:02&quot;,
                    &quot;DriverOpts&quot;: null
                }
            }
        }
    }
]
</code></pre>
<p>And <code>telnet</code>:</p>
<pre class="lang-sh prettyprint-override"><code>telnet 0.0.0.0 4306
Trying 0.0.0.0...
telnet: Unable to connect to remote host: Connection refused
</code></pre>
<pre class="lang-sh prettyprint-override"><code>telnet 172.17.0.1 4306
Trying 172.17.0.1...
Connected to 172.17.0.1.
</code></pre>
<p>By default the test uses <code>jdbc:mysql://0.0.0.0:4306/db</code>, but if I change this to <code>jdbc:mysql://172.17.0.1:4306/db</code> it's able to connect.</p>
<p>I tried using <code>postgres</code> instead of <code>mysql</code> and had the same problem.</p>
<p>My question is why it's unable to connect to <code>0.0.0.0</code>? Is it because it's a container in a container in a pod? I'm new to this technology.</p>

wilmol
<p><code>0.0.0.0</code> is not even an <a href="https://en.wikipedia.org/wiki/0.0.0.0" rel="nofollow noreferrer">address</a> 🤷, so I wouldn't expect that to work. It's typically used on servers/services to bind to <code>any</code> IP address (or meaning not applicable) but not by clients trying to connect to a server/service. If you are really connecting locally you could use <code>localhost</code> (DNS canonical) or just <code>127.0.0.1</code>. You didn't specify the connection string on your test but it could be that it's just connecting to the local socket <code>/var/lib/mysql/mysql.sock</code> instead of the IP address (❓)</p>
<p><code>172.17.0.1</code> is the local container address so that's always going to work as long as you expose the port, but the issue is that your container may not always have the same address depending on what's running on the specific machine where you are instantiating the container.</p>
<p>✌️</p>
