Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yesod app in Docker container can't make network requests

I have a Yesod app which I am deploying to Heroku in a Docker container. The app uses Amazon SES to send emails. When running the app locally using yesod devel this works fine, but in the container on Heroku I get the following error:

HttpExceptionRequest Request {
  host                 = "email.eu-west-1.amazonaws.com"
  port                 = 443
  secure               = True
  requestHeaders       = [("Content-Type","application/x-www-form-
urlencoded"),("Date","Wed, 20 Sep 2017 12:39:49 +0000"),("X-Amzn-
Authorization","AWS3-HTTPS AWSAccessKeyId=AKIAIBUN4ZEOKYKOB35A, 
Algorithm=HmacSHA256, 
Signature=xh3fi4EJOAe0LOZVCng5NRZIw2D+6P++0aO4Q5Dy0gw=")]
  path                 = "/"
  queryString          = ""
  method               = "POST"
  proxy                = Nothing
  rawBody              = False
  redirectCount        = 10
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
}
 (ConnectionFailure Network.BSD.getProtocolByName: does not exist (no 
such protocol name: tcp))

I'm thinking I might need to install some extra packages in the container. Here's the Dockerfile:

FROM ubuntu:17.04

RUN apt-get update && apt-get install -y libpq-dev

WORKDIR /app

ADD . /app

EXPOSE 8080

ENV PGHOST localhost

CMD "./run"
like image 317
Will Avatar asked Sep 20 '17 12:09

Will


1 Answers

Thanks to Michael Snoyman's hint, I found that netbase is the package required to populate /etc/protocols. After installing that, I got a new error complaining that the SSL cert for Amazon SES was from an unknown certificate authority.

I installed the ca-certificates package, and this went away. I also came across an error telling me that libstdc++6 was not installed - so I installed that. All working now.

My final Dockerfile that works with Yesod, using email auth and Amazon SES to send emails, is as follows (the "run" command is the compiled executable from stack build):

FROM ubuntu:17.04

RUN apt-get update && apt-get install -y libpq-dev libgnutls30 netbase libstdc++6 ca-certificates

WORKDIR /app

ADD . /app

EXPOSE 8080

ENV PGHOST localhost

CMD "./run"

Hooray for trial and error :)

like image 196
Will Avatar answered Nov 01 '22 13:11

Will