简体   繁体   English

Docker容器中的Yesod应用无法发出网络请求

[英]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. 我有一个Yesod应用,该应用正在Docker容器中部署到Heroku。 The app uses Amazon SES to send emails. 该应用程序使用Amazon SES发送电子邮件。 When running the app locally using yesod devel this works fine, but in the container on Heroku I get the following error: 使用yesod devel在本地运行应用程序时,此方法运行良好,但在Heroku上的容器中,出现以下错误:

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: 这是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"

Thanks to Michael Snoyman's hint, I found that netbase is the package required to populate /etc/protocols . 感谢Michael Snoyman的提示,我发现netbase是填充/etc/protocols所需的软件包。 After installing that, I got a new error complaining that the SSL cert for Amazon SES was from an unknown certificate authority. 安装后,我收到一个新错误,抱怨Amazon SES的SSL证书来自未知的证书颁发机构。

I installed the ca-certificates package, and this went away. 我安装了ca-certificates软件包,然后消失了。 I also came across an error telling me that libstdc++6 was not installed - so I installed that. 我还遇到一个错误,告诉我没有安装libstdc++6所以我安装了它。 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 ): 我最终的与Yesod一起使用的Dockerfile是使用电子邮件身份验证和Amazon SES发送电子邮件的,如下所示(“运行”命令是从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 :) 万岁反复试验:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM