Deployment Rails app for Docker

2019-07-14 03:44发布

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) access to the logs from previously deployed container which can be stopped/destroyed. Rsyslog/syslog?

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) how to provision Dockerfile with Ansible or alternatives? Otherwise what are pitfalls of Dockerfile bash-like style?

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

1条回答
够拽才男人
2楼-- · 2019-07-14 04:11

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

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

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?

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.

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) how to provision Dockerfile with Ansible or alternatives? Otherwise what are pitfalls of Dockerfile bash-like style?

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) what is the best way to access to Rails console through Docker?

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

docker attach <container-id>

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

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.

查看更多
登录 后发表回答