重新构建在Docker容器中运行的Go(App Engine)应用程序?

huangapple go评论98阅读模式
英文:

Re-build Go (App Engine) app running inside docker container?

问题

通常情况下,当你使用Go-Appengine的goapp serve命令运行Go应用程序时,文件更改会被检测到并触发重新构建。

INFO     2015-01-11 ... 检测到文件更改: ...

我目前正在尝试在Docker容器中运行Go-Appengine,虽然服务器能够正确启动,但文件更改并没有触发重新构建。我该如何实现这一点?

根据我的个人经验,当检测到文件更改时,在Docker容器内外运行的Django项目表现相同。

英文:

Normally, when you run a Go app using Go-Appengine's goapp serve command, file changes are detected and initiate a re-build.

INFO     2015-01-11 ... Detected file changes: ...

I'm currently experimenting with running Go-Appengine inside a docker container, and while the server starts appropriately, file changes do not initiate a re-build. How do I make this happen?

From my personal experience, Django projects running inside and outside docker containers behave the same way when file changes are detected.

答案1

得分: 1

我认为问题在于文件在 Docker 容器内部不会改变,只会在主机文件系统上改变。你的源代码目录是在 Dockerfile 中添加的(当构建容器镜像时)。如果你稍后更改了文件,容器不会自动重新构建。

为了解决这个问题(用于开发目的),你可以将主机系统中的源代码目录挂载到 Docker 容器中。通过这个技巧,源代码的更改会自动添加到容器中。

要实现这一点,请添加以下内容:

volumes:
  - .:/go/src
英文:

I think the problem here is that the files don't change inside the docker-container, only on the host-filesystem. Your source-directory is added in the Dockerfile (when the container-image is built). If you change the files later, the container is not automatically rebuilt.

To solve this issue (for development-purposes) you could mount the source-directory from your host-system into the docker-container. with this trick, source-changes are automatically added to the container.

To to this, add

volumes:
  - .:/go/src

huangapple
  • 本文由 发表于 2015年1月11日 23:03:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/27888496.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定