rails mysql redis 的開發環境node
首先構建本身的鏡像mysql
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"]
使用mysql redis,數據庫配置裏host要寫成 mysql, redisweb
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