Reputation: 2314
I've created Ruby on Rails project with Nginx. Rails app and Nginx runs in separate and linked containers. This configuration works fine. However...
1) Is it possible to run both together (Rails / Puma server + Nginx) in a single container?
2) How should the CMD command in Dockerfile look like?
3) What command should I use as the "command:" attribute in docker-compose.yml?
I think that configuration to run them in separate containers is better solution, but I would like to get to know all possibilites.
I use Puma as a Rails' app server and to run it I use command: bundle exec puma -C config/puma.rb
Upvotes: 1
Views: 1482
Reputation: 431
By default, docker monitors one single process, and the container is finished / relaunched (depending on launch flags) when this monitored process ends.
There is a specific distribution which aims at doing what you are pursuing, i.e., have more than one process alive in the docker instance while monitoring / restarting all of them, this image is phusion/baseimage, you will find it here: https://github.com/phusion/baseimage-docker
On this image, what you do is that you create as many services as you want by creating subdirectories under /etc/service, and launching as CMD the one who will start and monitor all the services, like this:
# Use phusion/baseimage as base image. To make your builds reproducible, make
# sure you lock down to a specific version, not to `latest`!
# See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for
# a list of version numbers.
FROM phusion/baseimage:<VERSION>
# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]
# ...put your own build instructions here...
# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
After that, just ensure you are creating a folder per service under /etc/service, and that inside there is a file called "run". This will be the entry point for your service, an example (from the doc) of the Dockerfile:
RUN mkdir /etc/service/memcached
ADD memcached.sh /etc/service/memcached/run
So for your target, just create a couple of folders + run file, one for NGINX and other for the Rails/Puma server, and use this image as base.
Upvotes: 3