简体   繁体   中英

Bundler can't see gems in a dockerized environment

I've been trying to dockerize a rails application for azure web containers. All seems to go well in the creation process, bundler runs and apparently installs the gems. However, when I ssh into it and go into the app directory to run the rails console i get the error message that rails isn't installed. I've tried running it both with bundle exec and without, and I've even tried to run the compiled console manually, but that just throws the error that rake isn't installed. I've been racking my brain with this for days now and I've tried countless configurations of the Dockerfile but nothing seems to work. Here's my current Dockerfile for reference.

FROM ruby:2.6.3

ENV SSH_PASSWD "root:Docker!"

# Update and install packages
RUN apt-get update \
       && apt-get install -y build-essential libpq-dev nodejs \
       && apt-get install -y --no-install-recommends openssh-server \
       && echo "$SSH_PASSWD" | chpasswd  \
       && curl -sL https://deb.nodesource.com/setup_11.x | bash - \
       && apt-get install -y nodejs \
       && npm install -g yarn

# Bundler config
ENV GEM_HOME=/bundle
ENV BUNDLE_PATH $GEM_HOME
ENV BUNDLE_APP_CONFIG=$BUNDLE_PATH \
BUNDLE_BIN=$BUNDLE_PATH/bin
ENV PATH /app/bin:$BUNDLE_BIN:$PATH

# Upgrade rubygems
RUN gem update --system

# Set working directory
RUN mkdir /app
WORKDIR /app

# Copy Files
COPY Gemfile* package.json yarn.lock ./
COPY sshd_config /etc/ssh/
COPY init.sh /usr/local/bin/

# Set permissions for init script
RUN chmod u+x /usr/local/bin/init.sh

# Install bundler and gems
RUN bundle install
RUN yarn install --check-files

#Copy Code
COPY . ./
EXPOSE 3000 2222

ENTRYPOINT [ "init.sh" ]

For this one, try running 'bundle config' as your environment may already be configured to have bundler use the default files. Once bundler sets a config in your environment, all successive bundle runs will use that config. Here's a sample of part of our app.sh that runs as the entrypoint/command. This script removes the 'production' flags and installs dev dependencies if it's a dev build just before running the puma server.

#!/usr/bin/env bash if [[ "$RAILS_ENV" == "development" ]] || [[ "$RAILS_ENV" == "test" ]]; then echo "--> Installing development and test bundles" bundle config --delete without bundle install --with development,test else echo "--> Installing production bundles" bundle install fi

In our case, we needed to delete the without clause as that was preventing installed gems from running during bundle install.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM