Yêu cầu thg 3 26, 2019 3:23 SA 111 0 0
  • 111 0 0
-5

Docker hoá Rails project

Chia sẻ
  • 111 0 0

Mọi người giúp mình xem Dockerfile và docker-compose.yml của mình sai ở đâu với. Mình đã cài cả bundler lẫn rake rồi nhưng vẫn không chạy được.

Dockerfile:

FROM ruby:2.5.3

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get install nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn

RUN gem update --system
RUN gem install rake
RUN gem install bundler
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
COPY Gemfile* /usr/src/app/
RUN bundler install
RUN bundle update
RUN bundle install --path vendor/cache
COPY . /usr/src/app/

docker-compose.yml

version: '3'
services:
db:
image: mysql:8.0.13
ports:
- "3306:3306"
volumes:
- db-data:/var/lib/mysql
env_file:
- .env.development

web:
build: .
command: /bin/sh -c "bundle exec rails server --host '0.0.0.0'"
ports:
- "8888:8888"
volumes:
- .:/usr/src/app
environment:
RAILS_ENV: development
env_file:
- .env.development
depends_on:
- db

volumes:
db-data:

Link git: https://github.com/BlazingRockStorm/let-us-go/tree/docker

thg 5 17, 2019 4:09 SA

bạn có thể tham khảo docker config này


Dockerfile

FROM ruby:2.4.0-alpine

ENV APP_ROOT /your_app

# Configure the main working directory. This is the base
# directory used in any further RUN, COPY, and ENTRYPOINT
# commands.

# RUN mkdir -p $APP_ROOT
WORKDIR $APP_ROOT

# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000

# Install apt based dependencies required to run Rails as
# well as RubyGems. As the Ruby image itself is based on a
# Debian image, we use apt-get to install those.
RUN apk update && \
    apk upgrade && \
    apk add --update --virtual build-dependencies \
    git \
    bash curl-dev ruby-dev build-base\
    zlib-dev libxml2-dev libxslt-dev tzdata yaml-dev mysql-dev \
    ruby-json yaml nodejs \
    linux-headers && \
    rm -rf /var/cache/apk/*

# Copy the Gemfile as well as the Gemfile.lock and install
# the RubyGems. This is a separate step so the dependencies
# will be cached unless changes to one of those two files
# are made.
COPY Gemfile Gemfile.lock ./
RUN gem install bundler && \
    bundle config build.nokogiri --use-system-libraries && \
    QMAKE=/usr/lib/qt5/bin/qmake bundle install && \
    bundle clean

# Copy the main application.
COPY . ./
CMD ["fuser, "-n", "tcp", "-k", "3000", "bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

your_app:
  build: .
  command: bundle exec rails s -p 3000 -b '0.0.0.0'
  environment:
    DATABASE_HOST: '...'
    DATABASE_USER: '...'
    DATABASE_PASSWORD: ''
  volumes:
    - .:/app
  ports:
    - "3000:3000"
  links:
    - db
  tty: true
  stdin_open: true
db:
  image: mysql:5.7.18
  environment:
    MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    #MYSQL_ALLOW_EMPTY_PASSWORD: 'no'
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí