【问题标题】:Go & Docker: I'm able to run a go web server when using stdlib, when I use custom packages errors occurGo & Docker:我可以在使用 stdlib 时运行 Go Web 服务器,当我使用自定义包时会出现错误
【发布时间】:2015-11-07 06:56:32
【问题描述】:

请注意,当我在笔记本电脑上运行代码时,代码运行良好。

以下两组代码将在我的笔记本电脑上运行。但是,第二组(使用我的自定义包)在运行 docker 的 Elastic Beanstalk 上不起作用。

仅限标准库

import (
    "net/http"
    "os"
)

func main() {
    port := os.Getenv("PORT")
    if port == "" {
        port = "3000"
    }
    http.ListenAndServe(":"+port, nil)
}

使用自定义包

import (
    "os"

    "github.com/sim/handlers"
)

func main() {
    port := os.Getenv("PORT")
    if port == "" {
        port = "3000"
    }
    handlers.ServeAndHandle(port) // wrapper of ListenAndServe
}

错误信息

Failed to build Docker image aws_beanstalk/staging-app: andlers: exit status 128 [0mtime="2015-08-14T05:08:17Z" level="info" msg="The command [/bin/sh -c go-wrapper download] returned a non-zero code: 1" . Check snapshot logs for details.

2015-08-14 01:08:15 UTC-0400    WARN    Failed to build Docker image aws_beanstalk/staging-app, retrying...

cron.yaml

version: 1
cron: 
  - name: "task1"
    url: "/scheduled"
    schedule: "* * * * *"

【问题讨论】:

  • 你用 docker 在你的机器上试过了吗?可能只是包的一些依赖项,它存在于您的机器上,但在您在弹性 beantalk 中使用的 docker 映像中缺失。
  • 你也可以发布你的 Dockerfile 吗?
  • @ydaetskcoR 我没有 dockerfile。我认为 Elastic beanstalk 会为您服务。也许我应该创建一个。

标签: amazon-web-services go docker amazon-elastic-beanstalk


【解决方案1】:

根据documentation,您的环境需要Dockerfile 或/和Dockerrun.aws.json

Dockerfile

FROM FROM golang:1.3-onbuild

EXPOSE 3000

CMD ["go run <your.go.file>"]

Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "golang:1.3-onbuild",   # <-- don't need this if you are using a Dockerfile
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "3000"
    }
  ],
  "Logging": "/var/log/go"
}

使用eb命令行部署?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-08
    • 2020-07-01
    • 2022-10-06
    • 1970-01-01
    • 2023-03-28
    • 2012-05-21
    • 2021-05-30
    • 2021-12-28
    相关资源
    最近更新 更多