Go&Docker:当我使用stdlib时,我能够运行go web服务器,当我使用自定义包时会发生错误

Chr*_*s W 5 go amazon-web-services docker amazon-elastic-beanstalk

请注意,当我在笔记本电脑上运行代码时,代码完全正常.

以下两组代码将在我的笔记本电脑上运行.但是第二组(使用我的自定义程序包)不适用于运行docker的Elastic Beanstalk.

仅限标准Lib

import (
    "net/http"
    "os"
)

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

使用自定义包

import (
    "os"

    "github.com/sim/handlers"
)

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

错误消息:

无法构建Docker镜像aws_beanstalk/staging-app:andlers:退出状态128 [0mtime ="2015-08-14T05:08:17Z"level ="info"msg ="命令[/ bin/sh -c go-wrapper下载]返回非零代码:1".检查快照日志以获取详细信

2015-08-14 01:08:15 UTC-0400 WARN无法构建Docker镜像aws_beanstalk/staging-app,正在重试...

cron.yaml

version: 1
cron: 
  - name: "task1"
    url: "/scheduled"
    schedule: "* * * * *"
Run Code Online (Sandbox Code Playgroud)

Ric*_*ico 0

根据文档,您的环境需要一个Dockerfile或/和Dockerrun.aws.json

Dockerfile

FROM FROM golang:1.3-onbuild

EXPOSE 3000

CMD ["go run <your.go.file>"]
Run Code Online (Sandbox Code Playgroud)

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"
}
Run Code Online (Sandbox Code Playgroud)

使用eb命令行部署?