0
1

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を使ったRuby on Rails6の環境構築

Last updated at Posted at 2021-03-23

Dockerとdocker-composeを使ってRuby on Rails6の環境を構築しました。

前提

Docker & docker-composeをインストール済み

動作環境

  • macOS Catalina 10.15.7
  • Docker 20.10.2
  • docker-compose 1.27.4

ディレクトリを作成します。

mkdir rails_api_docker
cd rails_api_docker

Gemfile Dockerfile docker-compose.ymlを作成します。

Gemfile
source 'https://rubygems.org'

gem 'rails', '6.0.3'
Dockerfile
FROM ruby:2.7.1-alpine3.11

ENV BUNDLER_VERSION=2.1.4

WORKDIR /usr/src/app

COPY Gemfile .
COPY Gemfile.lock .

RUN apk update && \
    apk add --no-cache \
    shared-mime-info \
    yarn \
    nodejs \
    linux-headers \
    libxml2-dev \
    curl-dev \
    make \
    gcc \
    libc-dev \
    g++ \
    sqlite-dev \
    tzdata && \
    gem install bundler && \
    bundle install

COPY . .

EXPOSE 3000
docker-compose.yml
version: '3'
services: 
  web:
    build: .
    ports: 
      - '3000:3000'
    volumes: 
      - .:/usr/src/app
    tty: true
    command: ["rails", "server", "-b", "0.0.0.0"]

docker-composeを使ってRailsアプリケーションを作成します。

docker-compose run web rails new . --force

もう一度Dockerイメージをビルドします。

docker-compose build

docker-composeを起動します。

docker-compose up

localhost:3000にアクセスし、以下が表示されれば成功です。
スクリーンショット 2021-03-24 0.22.56.png


読んでいただきありがとうございました!ご指摘やご意見などありましたらコメントしていただけると嬉しいです🐳

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?