This does not covers installation of docker and compose
Also, presuming myapp is already created
For this example RoR app Will have
- Web server
- Postgres DB
We'll start with the Dockerfile, which describes how to build our virtual environment to host a Rails app.
FROM ruby:2.2.0
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
RUN bundle install
ADD . /myapp
Docker Compose lets us define our containers and how they should be linked together with a simple yaml file.
db:
image: postgres
ports:
- "5432"
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
links:
- db
default: &default
adapter: postgresql
encoding: unicode
username: postgres
host: <%= ENV['MYAPP_DB_1_PORT_5432_TCP_ADDR'] %>
port: <%= ENV['MYAPP_DB_1_PORT_5432_TCP_PORT'] %>
pool: 5
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
docker-compose run web env
gem 'therubyracer', platforms: :ruby
docker-compose build
docker-compose run web rake db:create
docker-compose run web rake db:migrate
docker-compose up