├── Gemfile ├── Gemfile.lock ├── README.md ├── docker-compose.yml └── docker ├── gitignore ├── mysql ├── Dockerfile ├── charset.cnf └── password.yml ├── nginx ├── Dockerfile ├── default.conf └── nginx.conf └── rails ├── Dockerfile └── unicorn.rb /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'rails', '5.2.3' 3 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/utahka/rails-docker/ca64ba983eb36f22e0071622ca5ecf80d20d5909/Gemfile.lock -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nginx + Rails (unicorn) + MySQL environment 2 | ## 使い方 3 | 作ったモチベーションとか,ビルド方法などは Qiita にまとめてあるので,[こちら](http://qiita.com/utahkaA/items/772cd80b893cd5367f38)を参考ください. 4 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | app: 4 | build: 5 | context: . 6 | dockerfile: ./docker/rails/Dockerfile 7 | command: bundle exec unicorn -p 3000 -c /app/config/unicorn.rb 8 | # command: bundle exec rails s -p 3000 -b '0.0.0.0' 9 | ports: 10 | - '3000:3000' 11 | volumes: 12 | - /var/tmp 13 | - .:/app 14 | depends_on: 15 | - db 16 | extends: 17 | file: ./docker/mysql/password.yml 18 | service: password 19 | 20 | db: 21 | build: 22 | context: . 23 | dockerfile: ./docker/mysql/Dockerfile 24 | ports: 25 | - '3306:3306' 26 | volumes: 27 | - db_data:/var/lib/mysql 28 | extends: 29 | file: ./docker/mysql/password.yml 30 | service: password 31 | 32 | nginx: 33 | build: 34 | context: . 35 | dockerfile: ./docker/nginx/Dockerfile 36 | ports: 37 | - '80:80' 38 | volumes_from: 39 | - app 40 | 41 | volumes: 42 | db_data: 43 | -------------------------------------------------------------------------------- /docker/gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | ./docker/mysql/password.yml 3 | ./docker/mysql/volumes 4 | 5 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 6 | # 7 | # If you find yourself ignoring temporary files generated by your text editor 8 | # or operating system, you probably want to add a global ignore instead: 9 | # git config --global core.excludesfile '~/.gitignore_global' 10 | 11 | # Ignore bundler config. 12 | /.bundle 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/* 16 | /tmp/* 17 | !/log/.keep 18 | !/tmp/.keep 19 | 20 | # Ignore Byebug command history file. 21 | .byebug_history 22 | -------------------------------------------------------------------------------- /docker/mysql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mysql:5.7 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y apt-utils \ 5 | locales && \ 6 | rm -rf /var/lib/apt/lists/* && \ 7 | echo "ja_JP.UTF-8 UTF-8" > /etc/locale.gen && \ 8 | locale-gen ja_JP.UTF-8 9 | ENV LC_ALL ja_JP.UTF-8 10 | ADD ./docker/mysql/charset.cnf /etc/mysql/conf.d/charset.cnf 11 | -------------------------------------------------------------------------------- /docker/mysql/charset.cnf: -------------------------------------------------------------------------------- 1 | [mysqld] 2 | character-set-server=utf8mb4 3 | collation-server=utf8mb4_general_ci 4 | [client] 5 | default-character-set=utf8mb4 6 | -------------------------------------------------------------------------------- /docker/mysql/password.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | password: 4 | environment: 5 | MYSQL_ROOT_PASSWORD: password 6 | MYSQL_USER: hoge 7 | MYSQL_PASSWORD: hogepassword 8 | TZ: "Asia/Tokyo" 9 | -------------------------------------------------------------------------------- /docker/nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.16 2 | RUN apt-get update && \ 3 | apt-get install -y apt-utils \ 4 | locales && \ 5 | echo "ja_JP.UTF-8 UTF-8" > /etc/locale.gen && \ 6 | locale-gen ja_JP.UTF-8 7 | ENV LC_ALL ja_JP.UTF-8 8 | ADD ./docker/nginx/nginx.conf /etc/nginx/nginx.conf 9 | ADD ./docker/nginx/default.conf /etc/nginx/conf.d/default.conf 10 | -------------------------------------------------------------------------------- /docker/nginx/default.conf: -------------------------------------------------------------------------------- 1 | upstream unicorn { 2 | server unix:/var/tmp/unicorn.sock; 3 | } 4 | 5 | server { 6 | listen 80; 7 | server_name localhost; 8 | 9 | #charset koi8-r; 10 | #access_log /var/log/nginx/host.access.log main; 11 | 12 | location / { 13 | proxy_pass http://unicorn; 14 | } 15 | 16 | #error_page 404 /404.html; 17 | 18 | # redirect server error pages to the static page /50x.html 19 | # 20 | error_page 500 502 503 504 /50x.html; 21 | location = /50x.html { 22 | root /usr/share/nginx/html; 23 | } 24 | 25 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 26 | # 27 | #location ~ \.php$ { 28 | # proxy_pass http://127.0.0.1; 29 | #} 30 | 31 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 32 | # 33 | #location ~ \.php$ { 34 | # root html; 35 | # fastcgi_pass 127.0.0.1:9000; 36 | # fastcgi_index index.php; 37 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 38 | # include fastcgi_params; 39 | #} 40 | 41 | # deny access to .htaccess files, if Apache's document root 42 | # concurs with nginx's one 43 | # 44 | #location ~ /\.ht { 45 | # deny all; 46 | #} 47 | } 48 | 49 | -------------------------------------------------------------------------------- /docker/nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | user nginx; 3 | worker_processes 1; 4 | 5 | error_log /var/log/nginx/error.log warn; 6 | pid /var/run/nginx.pid; 7 | 8 | 9 | events { 10 | worker_connections 1024; 11 | } 12 | 13 | 14 | http { 15 | include /etc/nginx/mime.types; 16 | default_type application/octet-stream; 17 | 18 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 | '$status $body_bytes_sent "$http_referer" ' 20 | '"$http_user_agent" "$http_x_forwarded_for"'; 21 | 22 | access_log /var/log/nginx/access.log main; 23 | 24 | sendfile on; 25 | #tcp_nopush on; 26 | 27 | keepalive_timeout 65; 28 | 29 | #gzip on; 30 | 31 | include /etc/nginx/conf.d/*.conf; 32 | } 33 | -------------------------------------------------------------------------------- /docker/rails/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.6.3 2 | RUN apt-get update -qq && \ 3 | apt-get install -y apt-utils \ 4 | build-essential \ 5 | libpq-dev \ 6 | nodejs \ 7 | default-mysql-client 8 | RUN mkdir /app 9 | WORKDIR /app 10 | ADD Gemfile /app/Gemfile 11 | ADD Gemfile.lock /app/Gemfile.lock 12 | RUN bundle install -j4 13 | ADD . /app 14 | 15 | EXPOSE 3000 16 | -------------------------------------------------------------------------------- /docker/rails/unicorn.rb: -------------------------------------------------------------------------------- 1 | worker_processes 8 2 | 3 | pid "/var/run/unicorn.pid" 4 | listen "/var/tmp/unicorn.sock" 5 | 6 | stdout_path "./log/unicorn.stdout.log" 7 | stderr_path "./log/unicorn.stderr.log" 8 | --------------------------------------------------------------------------------