[Haskell-cafe] Static executables in minimal Docker containers

Michael Snoyman michael at snoyman.com
Mon Apr 13 08:54:14 UTC 2015


I'm trying to put together a minimal Docker container consisting of nothing
but GHC-compiled static executables. Below you can see a full interaction
I've had with GHC and Docker. The high level summary is that:

* When compiled statically, the executable runs just fine in both my host
OS (Ubuntu 14.04) and an Ubuntu 14.04 Docker image
* That same executable run from a busybox (or a "scratch" image, not shown
here since it's slightly longer to set up) hangs and then runs out of memory

I've watched the process in top, and it uses up a huge amount of CPU and
memory. I get the same behavior whether I compiled with or without
optimizations or the multithreaded runtime. I also get identical behavior
with both GHC 7.8.4 and 7.10.1.

I'm not sure how best to proceed with trying to debug this, any suggestions?

vagrant at vagrant-ubuntu-trusty-64:~/Desktop$ cat > hello.hs <<EOF
main :: IO ()
main = putStrLn "Static Hello"
EOF
vagrant at vagrant-ubuntu-trusty-64:~/Desktop$ ghc -optl-static -optl-pthread
hello.hs -static
[1 of 1] Compiling Main             ( hello.hs, hello.o )
Linking hello ...
/opt/ghc/7.8.4/lib/ghc-7.8.4/rts-1.0/libHSrts.a(Linker.o): In function
`internal_dlopen':
(.text+0x5c): warning: Using 'dlopen' in statically linked applications
requires at runtime the shared libraries from the glibc version used for
linking
vagrant at vagrant-ubuntu-trusty-64:~/Desktop$ ./hello
Static Hello
vagrant at vagrant-ubuntu-trusty-64:~/Desktop$ docker run --rm -v
$(pwd)/hello:/usr/local/bin/hello:ro ubuntu:14.04 /usr/local/bin/hello
Static Hello
vagrant at vagrant-ubuntu-trusty-64:~/Desktop$ docker run --rm -v
$(pwd)/hello:/usr/local/bin/hello:ro busybox /usr/local/bin/hello
hello: out of memory (requested 1048576 bytes)
vagrant at vagrant-ubuntu-trusty-64:~/Desktop$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150413/f2170aa6/attachment.html>


More information about the Haskell-Cafe mailing list