5

The Issue

I am trying to create docker image with the Haskell application inside. however, the domain name resolution of hostnames of other containers in the network in my application inside docker container fails (but I am able to wget / ping other containers and their hostnames are correctly resolved).

To find the root cause I tried to resolve manually hostnames (using Network.DNS package) and use only IP addresses in servant-client. However this yields just cryptic error message:

Network.BSD.getProtocolByName: does not exist (no such protocol name: udp)

I think I am missing some packages inside my docker image. I've tried installing libc6-compat but without success (libc6 from Debian was used to compile Haskell application). Moreover /etc/protocols contains correct entries. What else is missing inside a docker image?

Docker images

The docker image I am using to run the application is alpine:3.6 - Whole dockerfile, there's not much in it. This is different image than used to build the application (It is ~20x smaller).

The docker image I am using to build the haskell app is based on debian:stretch. Dockerfile.

Whole source code with the build instructions is available here (Angular part can be skipped):

https://github.com/carbolymer/blockchain/tree/0b041875f71b2a09dc8568ee7b0cc22460fd5624

  • Have you tried strace? – melpomene Nov 12 '17 at 0:40
  • Inside Docker (running strace -p 1 as root): strace: attach: ptrace(PTRACE_ATTACH, 1): Operation not permitted – carbolymer Nov 12 '17 at 0:52
  • Does haskell build a binary that you run without an interpreter? i.e unlike java, ruby or nodejs which need an external binary to run code. – Matt Nov 12 '17 at 9:46
  • @Matt, yes, I am generating statically linked binary. – carbolymer Nov 12 '17 at 11:01
2

It sounds like you are missing some linked dependencies for your Haskell code to run.

Alpine uses musl libc to cutdown on size which means most standard linked binaries won't run from the standard distros as they use GNU libc. Either compile your app as normal in an alpine image or create a statically linked binary to run in any Linux distro/container.

The base Debian layer is shared between any image that uses it, so you're probably not saving as much space as you think in any case. If it's going to be easier to use the Debian image, then use that.

  • Yes, I am creating statically linked binary, here's build command: github.com/carbolymer/docker-images/blob/master/haskell-stack/… . I suppose the issue here is the network Haskell package, which still requires original glibc. The question here is, is musl libc compatible with GNU libc? Btw. The article you linked is outdated and does not work with ghc-8.2.1. – carbolymer Nov 12 '17 at 10:59
1

I couldn't manage to install GHC 8.2.1 on alpine + musl libc. As a workaround I tried to use alpine-glibc image, but it resulted in the segfaults whenever my application tried to resolve host names. It turns out, that this is known bug in glibc.

The solution is to use dynamically linked binary + alpine-glibc image + install gmp-dev additionally.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.