HTTP.jl in docker


#1

[SOLVED] here
I am trying to create a simple HTTP server running in docker and seem to be failing. Here is the simplest app: test_http.jl

using HTTP
HTTP.listen() do req::HTTP.Request
    req.target == "/" && return HTTP.Response(200, "OK")
end

and the dockerfile DockerfileJuliaHTTP

FROM julia:1.1.0

RUN julia -e 'using Pkg;Pkg.REPLMode.pkgstr("add HTTP  ;precompile");using HTTP'

WORKDIR  /root/code
ADD . /root/code

CMD julia -i test_http.jl

then I build the image like this
docker build -f DockerfileJuliaHTTP -t http-simple .

and start docker
docker run --rm -p 9090:8081 -it http-simple

I cannot access it using http://localhost:9090/ from the browser running on the host

Interestingly, if I login into that container. start julia and try to execute (note, it is 8081 port, since inside the container)
HTTP.request("GET","http://localhost:8081/")

I get those errors on the server

Error: error handling request
│   exception =
│    MethodError: no method matching (::getfield(Main, Symbol("##3#4")))(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
│    Closest candidates are:
│      #3(!Matched::HTTP.Messages.Request) at /root/code/test_http.jl:6
│    Stacktrace:
│     [1] macro expansion at /root/.julia/packages/HTTP/GN0Te/src/Servers.jl:352 [inlined]
│     [2] (::getfield(HTTP.Servers, Symbol("##13#14")){getfield(Main, Symbol("##3#4")),HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at ./task.jl:259
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356
┌ Error: error handling request
│   exception =
│    MethodError: no method matching (::getfield(Main, Symbol("##3#4")))(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
│    Closest candidates are:
│      #3(!Matched::HTTP.Messages.Request) at /root/code/test_http.jl:6
│    Stacktrace:
│     [1] macro expansion at /root/.julia/packages/HTTP/GN0Te/src/Servers.jl:352 [inlined]
│     [2] (::getfield(HTTP.Servers, Symbol("##13#14")){getfield(Main, Symbol("##3#4")),HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at ./task.jl:259
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356
┌ Error: error handling request
│   exception =
│    MethodError: no method matching (::getfield(Main, Symbol("##3#4")))(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
│    Closest candidates are:
│      #3(!Matched::HTTP.Messages.Request) at /root/code/test_http.jl:6
│    Stacktrace:
│     [1] macro expansion at /root/.julia/packages/HTTP/GN0Te/src/Servers.jl:352 [inlined]
│     [2] (::getfield(HTTP.Servers, Symbol("##13#14")){getfield(Main, Symbol("##3#4")),HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at ./task.jl:259
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356
┌ Error: error handling request
│   exception =
│    MethodError: no method matching (::getfield(Main, Symbol("##3#4")))(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
│    Closest candidates are:
│      #3(!Matched::HTTP.Messages.Request) at /root/code/test_http.jl:6
│    Stacktrace:
│     [1] macro expansion at /root/.julia/packages/HTTP/GN0Te/src/Servers.jl:352 [inlined]
│     [2] (::getfield(HTTP.Servers, Symbol("##13#14")){getfield(Main, Symbol("##3#4")),HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at ./task.jl:259
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356
┌ Error: error handling request
│   exception =
│    MethodError: no method matching (::getfield(Main, Symbol("##3#4")))(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
│    Closest candidates are:
│      #3(!Matched::HTTP.Messages.Request) at /root/code/test_http.jl:6
│    Stacktrace:
│     [1] macro expansion at /root/.julia/packages/HTTP/GN0Te/src/Servers.jl:352 [inlined]
│     [2] (::getfield(HTTP.Servers, Symbol("##13#14")){getfield(Main, Symbol("##3#4")),HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at ./task.jl:259
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356

and after a while bunch of those

└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356
┌ Warning: Connection Timeout: 💀    0↑🔒    0↓🔒  62s 127.0.0.1:8081:8081 ≣16
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:307
┌ Warning: Connection Timeout: 💀    0↑🔒    0↓🔒  63s 127.0.0.1:8081:8081 ≣16
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:307
┌ Warning: Connection Timeout: 💀    0↑🔒    0↓🔒  64s 127.0.0.1:8081:8081 ≣16
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:307
┌ Warning: Connection Timeout: 💀    0↑🔒    0↓🔒  69s 127.0.0.1:8081:8081 ≣16
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:307
┌ Warning: Connection Timeout: 💀    0↑🔒    0↓🔒  62s 127.0.0.1:8081:8081 ≣16
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:307

In general the docker setup functions fine (downloading bunch of images, I can connect to them, no problem, all works out of the box).

My real app, which uses Bukdu.jl on top of HTTP.jl experiences similar problem: cannot connect to container from the host PC. Although I get one step further: If I login into container’s console and start running HTTP requests it runs all fine. Wonder if there is some configuration of the image/docker I am missing which seem to confuse HTTP.

I run
docker in Ubuntu 18.04.1 LTS inside VirtualBox on Windows 10


#2

Looks like it is not a docker problem

Installed Julia on above mentioned Ubuntu setup and getting very same issue.
Error: error handling request

│   exception =
│    MethodError: no method matching (::getfield(Main, Symbol("##3#4")))(::HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}})
│    Closest candidates are:
│      #3(::HTTP.Messages.Request) at REPL[3]:2
│    Stacktrace:
│     [1] macro expansion at /home/sd/.julia/packages/HTTP/GN0Te/src/Servers.jl:352 [inlined]
│     [2] (::getfield(HTTP.Servers, Symbol("##13#14")){getfield(Main, Symbol("##3#4")),HTTP.ConnectionPool.Transaction{Sockets.TCPSocket},HTTP.Streams.Stream{HTTP.Messages.Request,HTTP.ConnectionPool.Transaction{Sockets.TCPSocket}}})() at ./task.jl:259
└ @ HTTP.Servers ~/.julia/packages/HTTP/GN0Te/src/Servers.jl:356

and since it is very fresh install of julia, here is how HTTP got installed

(v1.1) pkg> add HTTP
   Cloning default registries into `~/.julia`
   Cloning registry from "https://github.com/JuliaRegistries/General.git"
     Added registry `General` to `~/.julia/registries/General`
 Resolving package versions...
 Installed IniFile ──────── v0.5.0
 Installed BinaryProvider ─ v0.5.3
 Installed HTTP ─────────── v0.8.0
 Installed MbedTLS ──────── v0.6.7
  Updating `~/.julia/environments/v1.1/Project.toml`
  [cd3eb016] + HTTP v0.8.0
  Updating `~/.julia/environments/v1.1/Manifest.toml`
  [b99e7846] + BinaryProvider v0.5.3
  [cd3eb016] + HTTP v0.8.0
  [83e8ac13] + IniFile v0.5.0
  [739be429] + MbedTLS v0.6.7
  [2a0f44e3] + Base64 
  [ade2ca70] + Dates 
  [8ba89e20] + Distributed 
  [b77e0a4c] + InteractiveUtils 
  [76f85450] + LibGit2 
  [8f399da3] + Libdl 
  [56ddb016] + Logging 
  [d6f4376e] + Markdown 
  [44cfe95a] + Pkg 
  [de0858da] + Printf 
  [3fa0cd96] + REPL 
  [9a3f8284] + Random 
  [ea8e919c] + SHA 
  [9e88b42a] + Serialization 
  [6462fe0b] + Sockets 
  [8dfed614] + Test 
  [cf7118a7] + UUIDs 
  [4ec0a83e] + Unicode 
  Building MbedTLS → `~/.julia/packages/MbedTLS/XkQiX/deps/build.log`

submitted issue to HTTP.jl


#3

Well looks like it is back to docker. I have a working HTTP.jl in linux now. and it still fails in the docker environment

Here is the code which works fine in linux

using HTTP
HTTP.listen("127.0.0.1", 8080, verbose = true) do http
        write(http,  "OK")
end

yet, if I create docker image (as per original post )

FROM julia:1.1.0

RUN julia -e 'using Pkg;Pkg.REPLMode.pkgstr("add HTTP  ;precompile");using HTTP'

WORKDIR  /root/code
ADD . /root/code

CMD julia -i test_http.jl

and start it
docker run --rm -it -p 8080:8080 http-simple

I cannot connect to container from the host browser/curl. yet if I login in container’s console. curl works just fine within the container.


#4

[SOLVED] so looks like I need to bind to 0.0.0.0 instead on 127.0.0.1 in docker. The following code works in docker

using HTTP
HTTP.listen("0.0.0.0", 8080, verbose = true) do http
        write(http,  "OK")
end