DockerでのRails開発環境構築

# Dockerfile
FROM ruby:3.2.1

RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -

RUN apt-get update && apt-get install -y \
      git \
      nodejs \
      vim

RUN npm install -g yarn

RUN gem install bundler

WORKDIR /app

RUN bundle config set path vendor/bundle
CMD ["bash"]
# docker-compose.yaml
version: "3"
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      HISTFILE: "/app/log/.bash_history"
    ports:
      - "3000:3000"
    # docker-compose upした後に起動したままにさせる
    tty: true
    # depends_on:
    volumes:
      - .:/app
      - rails_bundle:/app/vendor/bundle
      - node_modules:/app/node_modules

volumes:
  rails_bundle:
    driver: local
  node_modules:
    driver: local

docker-compose upで起動し、docker-compose exec app bashでシェルに接続する。

参考文献