0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Docker開発環境

Posted at

#はじめに
現在開発中のアプリにDockerを導入したのでアウトプットします。

#環境
Ruby on Rails '6.0.0'
Ruby '2.6.5'
MySQL '5.6.47'

Dockerfile

開発中アプリのルートディレクトリにDockerfileを作成します。

Dockerfile
FROM ruby:2.6.5

RUN apt-get update -qq && \
    apt-get install -y build-essential \
                       libpq-dev \
                       nodejs

RUN mkdir /アプリ名
WORKDIR /アプリ名

ADD ./Gemfile /アプリ名/Gemfile
ADD ./Gemfile.lock /live_search/Gemfile.lock

RUN gem install bundler
RUN bundle install
ADD . /アプリ名

docker-compose.yml

docker-compose.yml
version: '3'
services:
  db:
    image: mysql:5.6.47
    environment:
      MYSQL_ROOT_PASSWORD: 'password'
    ports:
      - "4306:3306"
    volumes:
      - ./db/mysql-data:/var/lib/mysql

  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/アプリ名
    ports:
      - "3000:3000"
    depends_on:
      - db

entrypoint.sh

entrypoint.sh
set -e

rm -f /myapp/tmp/pids/server.pid

exec "$@"

database.yml

database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: password
  host: db
  socket: /tmp/mysql.sock

password: password
host: db
を追加

コンテナを作成

ターミナル
% docker-compose build

DB作成、migrationの実行

ターミナル
% docker-compose run web bundle exec rake db:create
% docker-compose run web bundle exec rake db:migrate

コンテナを起動

ターミナル
% docker-compose up 
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?