Docker Build w/ Sockets connection refused (ECONNREFUSED)

I have been building sysimages with PackageCompiler in docker without issue until recently. I recently add some functions that require Sockets networking. To exercise the function in the PackageCompiler.jl tracing script I have a simple server/client setup via

errormonitor(@async begin
    server = listen(IPv4(0), 2002)
    sock = accept(server)
    while isopen(sock)
        ...
    end
end)

client = connect(IPv4(0), 2002)

This runs without issue on my host machine (OSX). It also runs without issue when executed inside the container in interactive mode (ubuntu:18.04). However, it fails when run in a Dockerfile as part of docker build producing

#21 12.65 ERROR: LoadError: IOError: connect: connection refused (ECONNREFUSED)
#21 13.44 Stacktrace:
#21 13.44  [1] wait_connected(x::TCPSocket)
#21 13.83    @ Sockets /julia-1.7.2/share/julia/stdlib/v1.7/Sockets/src/Sockets.jl:532
#21 14.01  [2] connect
#21 14.01    @ /julia-1.7.2/share/julia/stdlib/v1.7/Sockets/src/Sockets.jl:567 [inlined]
#21 14.01  [3] connect(addr::IPv4, port::Int64)
#21 14.01    @ Sockets /julia-1.7.2/share/julia/stdlib/v1.7/Sockets/src/Sockets.jl:553
#21 14.01  [4] top-level scope
#21 14.01    @ ~/scripts/precompilation_helpers.jl:23
#21 14.01  [5] include(fname::String)
#21 14.01    @ Base.MainInclude ./client.jl:451
#21 14.01  [6] top-level scope
#21 14.01    @ none:1
#21 14.01 in expression starting at /root/scripts/precompilation_helpers.jl:23

The closest discussion I’ve seen is Docker + Base.runtests("Sockets"). But I am explicitly using IPv4(0) and it works without issue in a build docker container, so I don’t think its related.

In summary, this networking script work fine in a docker container but fails if run as part of a docker build