Skip to content

Instantly share code, notes, and snippets.

@dtelaroli
Last active June 29, 2018 16:45
Show Gist options
  • Save dtelaroli/4d4c5fddb743ef676aa2d4e9bf10ada9 to your computer and use it in GitHub Desktop.
Save dtelaroli/4d4c5fddb743ef676aa2d4e9bf10ada9 to your computer and use it in GitHub Desktop.
Docker get started with rails, mysql and nginx
APP_PATH=/var/www
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=development
MYSQL_USER=user
MYSQL_PASSWORD=pass

Docker

Exemple

https://github.com/dtelaroli/docker-rails

Documentation

https://docs.docker.com/get-started/

Installation

Building docker image

docker build -t my . --build-arg USER=$USER --build-arg UID=$(id -u)

Creating Rails APP

docker run -v $PWD:/var/www/app -it my rails new .

Configuring app

docker-compose run myapp bundle install
docker-compose run myapp rails db:migrate

Running docker-compose

docker-compose up

Connecting to machine

docker run -it my bash
docker-compose run myapp bash

Cleaning

# Clean project
docker-compose down

# Clean machine
docker system prune -a
upstream puma {
server myapp:3000;
}
server {
listen 80;
server_name localhost;
root /var/www/app/public;
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
# limit_req zone=one;
}
}
development:
adapter: mysql2
encoding: utf8
pool: 15
username: root
password: root
host: mydb
database: development
version: '3.4'
services:
myapp:
container_name: myapp
image: my
env_file: .env
volumes:
- bundle:/usr/local/bundle
- $PWD:/var/www/app
ports:
- '3000:3000'
links:
- mydb
networks:
- mynet
command: rails s -b 0.0.0.0
mydb:
container_name: mydb
image: library/mysql:5.6.22
ports:
- 3306:3306
env_file: .env
networks:
- mynet
mynginx:
container_name: mynginx
image: nginx:alpine
volumes:
- ./app.conf:/etc/nginx/conf.d/default.conf
ports:
- '80:80'
links:
- myapp
networks:
- mynet
volumes:
bundle:
name: bundle
networks:
mynet:
# From one of the official ruby images
FROM ruby:2.4.3
LABEL [email protected]
ARG USER
ARG UID
ARG APP_PATH=/var/www
RUN echo "RUN env=$RAILS_ENV UID=$UID USER=$USER"
RUN addgroup --gid $UID $USER && \
adduser --system --gid $UID --uid $UID $USER && \
mkdir -p $APP_PATH && \
chown -R $USER:$USER $APP_PATH /usr/local/bundle
RUN mkdir -p $APP_PATH/app && chown -R $USER:$USER $APP_PATH
RUN curl -sS http://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update
RUN apt-get -y install node yarn
USER $USER
WORKDIR ${APP_PATH}/app
RUN gem install rails
CMD bash
gem 'mysql2'
gem 'mini_racer', platforms: :ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment