在Docker上安装运行时是否有意义?

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

Does it make sense to install the runtime on docker?

问题

我正在考虑在Docker上部署一些应用程序(使用AWS Beanstalk作为提供商)。在查阅了各种资源后,我发现推荐使用基础镜像,对于我的情况来说,是官方的Golang镜像。但我想知道为什么需要在容器中安装运行时(即Golang)。难道在Docker容器中只需要部署二进制文件就可以了吗?

英文:

I'm considering deploying some apps on docker (aws beanstalk being the provider). Going though various resources I've found it's recommended to use a base images, in my case the official golang image but I'm wondering why would you need the runtime installed (i.e. Golang) on the container. Isn't the binary all you should deploy on the docker container?

答案1

得分: 1

我不是一个 Docker 爱好者,但一般来说,Go 运行时会被编译到你的二进制文件中,你不需要其他任何东西。Go 镜像包括了 SDK,并不是运行时。只有在你想要在容器中构建应用程序时才有用。否则你不需要它。

从该镜像的文档中可以看到:使用这个镜像的最简单方法是将一个 Go 容器同时作为构建和运行环境。

所以也许这只是一种在镜像上构建源代码的 Docker 模式,或者只是一些人在使用解释型语言时的习惯。个人在部署 Go 应用程序时(不使用 Docker),我会在 CI 机器上构建一个构件,然后部署该构件,而不是源代码。

英文:

I'm not a docker aficionado but in general, the Go runtime is compiled into your binary, and you don't need anything but that. The Go image includes the SDK, and is not the runtime. It's only useful if you want to build your app in the container. Otherwise you don't need it.

From that image's doc: The most straightforward way to use this image is to use a Go container as both the build and runtime environment.

So maybe it's a Docker pattern to just build your source on the image, or it's just a habit some people have from interpreted languages. Personally when I'm deploying Go applications (not via docker) I build an artifact on a CI machine and that's what I'm deploying, not the source.

答案2

得分: 0

我更喜欢静态编译,然后构建一个只包含所需用户空间的最小容器。这里有一个示例。

我个人喜欢在官方容器内构建,然后将二进制文件复制到我的部署容器中。我使用以下命令将 Docker 注入到我的构建容器中:

docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker)

这样,我就可以在构建容器中构建我的 Docker 容器,并通过 Dockerfile 的 ADD 命令添加二进制文件。

英文:

I prefer to statically compile and then build a minimal container with only the user-space you need, here is an example.

I personally like to build inside the official container and then copy the binary to my deployment container, I inject docker into my build container with something like this

docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker)

That way I build my docker container within my build container and just add the binary with a Dockerfile ADD

huangapple
  • 本文由 发表于 2014年12月18日 18:29:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/27544418.html
匿名

发表评论

匿名网友

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

确定