This is a little project of mine where I try to set up a Ruby on Rails production environment running on Docker. It is work in progress. Every step to get the application running should be provided here.
Notice: These steps are not considered "best practice". They're just the steps which got it working. I'm sure there is much room for improvement.
Todo:
- MySQL container
- Rails container using Unicorn
- Nginx as load balancer/reverse proxy
- Memcached for caching
- Sidekiq container for background jobs
- Use Brightbox Ruby Packages instead of RVM
- Using Docker Compose for orchestration
- Use data volume containers for Mysql data
- Fluentd for log collection
- Elasticsearch for log storage
- Kibana for log analysis
- MySQL Slave for backups
- Replace MySQL with Postgres
Environment: I am running this on a Mac using docker-machine.
Docker-Machine exposes all its ports on its IP address. This address is usually 192.168.59.103. It tells you
its IP when you run docker-machine env dev. To make reaching the vm more comfortable and to use the virtual
host feature I made an entry in my /etc/hosts:
192.168.99.100 beer.docker
All services within the docker-machine VM are now reachable via beer.docker: from my OS X command line.
First install docker-machine and the Docker command line tools. How this is done is very well documented all over the internet. Then start that whole stuff:
docker-machine start dev
eval "$(docker-machine env dev)"
docker-compose run web bundle exec rake db:setup
docker-compose up
All containers should now be running and you should be able to navigate your browser to the page http://beer.docker.
All containers are managed by docker-compose. You can see the configuration in the docker-compose.yml
file.
The nginx proxy container contains the docker-gen service. This listens for new and stopped containers.
As soon as a container with a VIRTUAL_HOST environment variable starts, it re-creates the nginx config file
and reloads nginx.
Scaling up the app is as easy as running docker-compose scale web=4. Now you have 4 running web containers.
The nginx proxy service acts as a load balancer in front of them.