Skip to content

graves/RbxNginxPostgresDocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Containerized Rails Development Environment using Docker

A sample Rails environment using three seperate Docker containers. Powered by Rubinius, Puma, Nginx and PostgreSQL.

Image Creation

These examples will tag the images "graves/image-name", feel free to modify this in any way you please. For each image first navigate to the directory containing the Dockerfile then run the build command.

Build the Rubinius/Rails image.

$ docker build -t="graves/rbx-rails" .

Build the Nginx image.

$ docker build -t="graves/nginx" .

Running the containers

Start the PostgreSQL server first with your desired options. Click the following link for details

$ docker run -p ::5432 \
--name postgresql \
-e POSTGRESQL_DB=docker_development \
-e POSTGRESQL_USER=docker \
-e POSTGRESQL_PASS=docker \
kamui/postgresql

Start your rails application. The SampleApp uses environment variables obtained from the linked postgres container to connect to the database. Check out config/database.yml if you need to make changes. There is a start_server.sh script passed to the root of the container during the build process. It uses foreman to create the databases, migrate, and start the puma server. Be sure to rebuild the server if you make changes to the startup script.

docker run --rm -i --name rails \
                    -e RAILS_ENV=development \
                    --link postgresql:db \
                    -v /Users/tg/Projects/sampleapp-docker/SampleApp:/var/www/SampleApp \
                    graves/rbx-rails

The -v option is a shared volume. Change this to match the path to your Rails application. Changes made to this directory on the host will be made available in the container without the need to rebuild or restart the container. Check out my blog post to see how this was made possible on OSX.

Finally start the Nginx container to proxy requests to your Rails app. Notice how I use a shared volume to allow the Nginx container access to Puma's unix domain socket. There is a startup script in the root of the Nginx container that chmods socket before starting Nginx.

docker run --rm -i --name nginx \
                    --volumes-from rails \
                    -p 80:80 \
                    -v /Users/tg/Projects/nginx-docker/var/log/nginx:/var/log/nginx \
                    graves/nginx

I'm on OSX so I use $ boot2docker ip to get the ip of the docker host and change my host file to map it to docker.local.

About

Docker containerized Rails application running on Rubinius, Nginx, and Postgresql

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors