为PostgreSQL和Golang创建Docker文件。

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

create docker file for postgresql and golang

问题

我有一个使用Go和PostgreSQL的项目。

创建DockerFile的最佳解决方案是什么?

是在Docker中使用操作系统(例如Ubuntu),然后安装Go和PostgreSQL?还是分别使用它们(使用Go和PostgreSQL,并在它们之间建立连接)?

英文:

I have project that uses Go and postgresql

What is the optimal solution for creating a DockerFile?

use os[for example ubuntu] in docker and install go and postgresql? or
use those separately[use go and postgresql and connection between them]?

答案1

得分: 4

Docker建议为每个任务使用一个容器,你可以参考多容器应用

我们一直在使用单个容器应用。但是,现在我们想要将MySQL添加到应用程序堆栈中。经常会出现以下问题:“MySQL将在哪里运行?将其安装在同一个容器中还是分开运行?”一般来说,每个容器应该只做一件事,并且做好这件事。有几个原因:

  • 你很可能需要以不同的方式扩展API和前端,而不是数据库
  • 分开的容器可以让你独立地进行版本控制和更新
  • 虽然你可能在本地使用容器作为数据库,但在生产环境中可能希望使用托管服务来管理数据库。你不希望将数据库引擎与应用程序一起发布。
  • 运行多个进程将需要一个进程管理器(容器只启动一个进程),这会增加容器启动/关闭的复杂性

还有更多原因。因此,我们将更新我们的应用程序以按照以下方式工作:

为PostgreSQL和Golang创建Docker文件。

所以,对于你来说,你应该选择在不同的容器中使用Go和PostgreSQL,并在它们之间建立连接

英文:

Docker suggest one container for one task, you could refers to Multi container apps:

> We have been working with single container apps. But, we now want to add MySQL to the application stack. The following question often arises - “Where will MySQL run? Install it in the same container or run it separately?” In general, each container should do one thing and do it well. A few reasons:
>
> * There’s a good chance you’d have to scale APIs and front-ends differently than databases
> * Separate containers let you version and update versions in isolation
> * While you may use a container for the database locally, you may want to use a managed service for the database in production. You don’t want to ship your database engine with your app then.
> * Running multiple processes will require a process manager (the container only starts one process), which adds complexity to container startup/shutdown
>
> And there are more reasons. So, we will update our application to work like this:
>
> 为PostgreSQL和Golang创建Docker文件。

So, for you, you should choose use go and postgresql in different containers and connection between them.

huangapple
  • 本文由 发表于 2021年9月1日 14:54:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/69009058.html
匿名

发表评论

匿名网友

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

确定