Rails Docker开发环境配置

rails mysql redis 的开发环境

首先构建自己的镜像

Dockerfile.development

FROM ruby:2.3.4-slim

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

RUN mkdir -p /app
WORKDIR /app

COPY Gemfile Gemfile.lock /app/
RUN gem install bundler && bundle install --jobs 20 --retry 5

COPY . /app

EXPOSE 4000

ENTRYPOINT ["bundle", "exec"]

CMD ["rails", "server", "-b", "0.0.0.0", "-p", "4000"]

docker-compose.yml 配置

使用mysql redis,数据库配置里host要写成 mysql, redis

version: '3'
services:
  mysql:
    image: mysql:5.7.17
    command: --sql-mode=""
    restart: always
    volumes:
      - ./mysql_data/:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: shiji_development

  redis:
    image: redis
    command: redis-server
    volumes:
      - ./redis_data:/data
    ports:
      - 6379:6379
  web:
    build:
      context: .
      dockerfile: Dockerfile.development
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 4000 -b '0.0.0.0'"
    stdin_open: true
    tty: true
    volumes:
      - .:/app
    ports:
      - "4000:4000"
    depends_on:
      - mysql
      - redis

    原文作者:lidashuang
    原文地址: https://segmentfault.com/a/1190000016808014
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞