Rails Docker开发环境配置

56次阅读

共计 851 个字符,预计需要花费 3 分钟才能阅读完成。

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 配置
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

正文完
 0