继续运行Docker容器内的GO HTTP服务器应用

发布于 2025-02-09 04:42:10 字数 527 浏览 1 评论 0原文

我有一个docker仅运行go我创建的二进制文件的容器,它是带有gin Framework的HTTP服务器。我不使用任何其他Web服务器,只需GO的内部HTTP服务器即可。在我的dockerfile在文件末尾我有:

EXPOSE 80

CMD ["/home/project/microservices/backend/engine/cmd/main"]

我使用docker-compose运行容器和重新启动:每个容器的始终。而且有效!

但是我的问题是,如果我创建的HTTP服务器因编程错误或其他原因而失败,它将重新启动?我该如何检查? Docker有这样的工具吗?

我尝试使用Substisord,但它存在一些问题,但我在运行它方面没有成功。

我希望有能力将HTTP服务器保持在容器内始终运行。

我能做些什么?

I have a Docker container that runs just a Go binary I created that is a http server with Gin framework. I don't use any other Web Server, just Go's internal http server. Inside my Dockerfile at the end of file I have this:

EXPOSE 80

CMD ["/home/project/microservices/backend/engine/cmd/main"]

I use docker-compose to run the container and restart: always for each container. And it works!

But my question is that, if the http server that I created fails due to programming error or something, It will restart? how can I check this? does Docker has tools for this?

I tried go with Supervisord but it has some problems and I was not successful on running it.

I want a workaround to keep the http server inside container always running.

What can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甩你一脸翔 2025-02-16 04:42:10

您可以尝试从主机杀死该过程。使用类似的内容找到过程ID

ps -aux | grep main

,然后使用Docker杀死它,

sudo kill <process id>

然后将其重新启动。通过使用,

docker ps

您应该看到“状态”已更改为UP 10秒之类的东西。

You can try killing the process from the host. Find the process id using something like

ps -aux | grep main

Then kill it using

sudo kill <process id>

Docker will then restart it. By using

docker ps

you should see that the 'status' has changed to something like Up 10 seconds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文