Go和Docker:当我使用stdlib时,我能够运行一个去web服务器,当我使用自定义包发生错误
注意,当我在笔记本电脑上运行代码时,代码工作得很好。
以下两组代码将在我的笔记本电脑上运行。 但是第二个组(使用我的自定义包)在运行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 }
错误消息:
无法构buildDocker镜像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无法构buildDocker镜像aws_beanstalk / staging-app,正在重试…
cron.yaml
version: 1 cron: - name: "task1" url: "/scheduled" schedule: "* * * * *"
根据文档,您需要为您的环境使用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
命令行进行部署?