适用于Docker的Deployment Rails应用 [英] Deployment Rails app for Docker

查看:88
本文介绍了适用于Docker的Deployment Rails应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读许多资源,但从部署的角度来看,仍然对Docker感到困惑。试图找出Docker环境中的Rails应用最佳实践,特别是有兴趣解决以下问题:

Read many resources but still confused about Docker from deployment point of view. Trying to find out the best practices for Rails app within Docker environment, particularly interested how to solve the following problems:

1)从以前部署的容器访问日志,停止/销毁。 Rsyslog / syslog?

1) access to the logs from previously deployed container which can be stopped/destroyed. Rsyslog/syslog?

2)回滚部署有多容易?就删除请求而言是否安全?您是否可以将USR2 + QUIT信号发送到图像,但继续从容地使用另一个图像来开始新的主人/工人? Nginx上游有多个映像端口?

2) how easy to rollback a deployment? Is that safe in terms of dropped requests? Can you send USR2+QUIT signals to the image but keep starting new master/workers with another image gracefully? Nginx upstream with multiple image ports?

3)如何为Dockerfile配置Ansible或替代方案?否则,什么是Dockerfile bash风格的陷阱?

3) how to provision Dockerfile with Ansible or alternatives? Otherwise what are pitfalls of Dockerfile bash-like style?

4)通过Docker访问Rails控制台的最佳方法是什么?

4) what is the best way to access to Rails console through Docker?

推荐答案


1)从先前部署的容器中访问日志,该日志可以停止/销毁。 Rsyslog / syslog吗?

1) access to the logs from previously deployed container which can be stopped/destroyed. Rsyslog/syslog?

一种选择是将日志发送到 ELK堆栈。使用 logtash-forwarder 日志快递 Beaver

One option is to send your logs to an ELK stack . Using logtash-forwarder or log-courier or Beaver


2)回滚部署有多容易?就删除请求而言是否安全?您是否可以将USR2 + QUIT信号发送到图像,但继续从容地用另一个图像来开始新的主人/工人? Nginx上游有多个图像端口?

2) how easy to rollback a deployment? Is that safe in terms of dropped requests? Can you send USR2 + QUIT signals to the image but keep starting new master/workers with another image gracefully? Nginx upstream with multiple image ports?

这是一个好问题。因此,如果您想优雅地终止会话,则必须与运行独角兽或其他工具的容器进行对话,并在容器内发出USR2 + QUIT信号,以优雅地处理会话终止。

This is a good question. So if you want to terminate your sessions gracefully you would have to talk to the container running unicorn or whatever and issue the USR2 + QUIT signals inside the container to handle session termination gracefully.

容器非常轻巧,因此无需重新启动nginx / unicorn,您只需使用新代码实例化新容器并终止nginx / unicorn进程,然后再使用旧代码终止容器即可。这里的技巧是管理容器并在容器内部发出命令的机制。不确定,但我认为 Kubernetes 可能对此具有某种机制。

Containers are pretty lightweight so instead of restarting your nginx/unicorn you could just instantiate new containers with new code and terminate the nginx/unicorn process before terminating the container with old code. The trick here is the mechanism to manage containers and issue commands inside the container. Not sure but I think Kubernetes may have a mechanism for this.


3)如何用Ansible或替代方式配置Dockerfile?否则,什么是Dockerfile bash风格的陷阱?

3) how to provision Dockerfile with Ansible or alternatives? Otherwise what are pitfalls of Dockerfile bash-like style?

这是您根据自己的想象力想做的更多事情。您可以模板化Dockerfile并运行 docker build 。或者,您可以使用类似 Ansible Docker模块之类的东西。 Dockerfile本质上是一本用于构建容器的运行手册,可以进行修改,放入源代码控制等。

This is more of how you would like to do it depending on your imagination. You can template Dockerfiles and have ansible run docker build. Or you can just use something like the Ansible Docker module . Dockerfile in essence is a runbook to build containers and can be modified, put into source control, etc.


4)最好的方法是什么要通过Docker访问Rails控制台?

4) what is the best way to access to Rails console through Docker?

为您的容器分配一个伪tty并使其具有交互性。然后您可以运行:

Assign a pseudo-tty to your container and make it interactive. Then you can run:

docker attach <container-id>

附加到容器,然后运行 bundle exec rails console 命令。

to attach to the container and then just run your bundle exec rails console command.

或者,您可以将容器的进程号设为 1 sshd 进程,然后可以SSH到容器并运行 bundle exec rails console 。这就是测试厨房 docker驱动程序

Alternatively, you can make your container's process number 1 the sshd process and you can then ssh to the container and run bundle exec rails console. This is how tools like test-kitchen with the docker-driver do it.

这篇关于适用于Docker的Deployment Rails应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆