# Docker Build w/ Sockets connection refused (ECONNREFUSED)

**URL:** <https://discourse.julialang.org/t/docker-build-w-sockets-connection-refused-econnrefused/85362>\
**Category:** General Usage\
**Created:** [August 5, 2022, 5:59pm UTC](https://discourse.julialang.org/t/docker-build-w-sockets-connection-refused-econnrefused/85362 "2022-08-05T17:59:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrPapa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drpapa/32/6835_2.png) [@DrPapa](https://discourse.julialang.org/u/DrPapa)\
**Post date:** [August 5, 2022, 5:59pm UTC](https://discourse.julialang.org/t/docker-build-w-sockets-connection-refused-econnrefused/85362/1 "2022-08-05T17:59:11Z")

</div>

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

```julia
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

```bash
#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")](https://discourse.julialang.org/t/docker-base-runtests-sockets/19435). 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
