最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby - Error during Docker build: bundle update net-pop command fails with exit code 34 in Rails app - Stack Overflow

programmeradmin0浏览0评论

Body:

I am trying to build my Docker container using the following command:

docker build --no-cache -t cryptoall .

But I am consistently getting this error:

43.55 (net-protocol (>= 0)).
43.55 Running `bundle update net-pop` should fix the problem.
------
Dockerfile:51
--------------------
 50 |     COPY Gemfile Gemfile.lock ./
 51 | >>> RUN bundle update net-pop && \
 52 | >>>     bundle install && \
 53 | >>>     rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
 54 | >>>     bundle exec bootsnap precompile --gemfile
 55 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c bundle update net-pop &&     bundle install &&     rm -rf ~/.bundle/ \"${BUNDLE_PATH}\"/ruby/*/cache \"${BUNDLE_PATH}\"/ruby/*/bundler/gems/*/.git &&     bundle exec bootsnap precompile --gemfile" did not complete successfully: exit code: 34

Dockerfile:

# syntax=docker/dockerfile:1

# This Dockerfile is designed for production, not development. Use with Kamal or 
# build'n'run by hand:
# docker build -t cryptoall .
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name 
# cryptoall cryptoall

# For a containerized dev environment, see Dev Containers: 
# .html

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.3.3
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base

# Rails app lives here
WORKDIR /rails

# Install base packages
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
    rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Set production environment
ENV RAILS_ENV="production" \
    BUNDLE_DEPLOYMENT="1" \
    BUNDLE_PATH="/usr/local/bundle" \
    BUNDLE_WITHOUT="development"

# Throw-away build stage to reduce size of final image
FROM base AS build

# Install packages needed to build gems, including dependencies for Nokogiri and others
RUN apt-get update -qq && \
    apt-get install --no-install-recommends -y \
      build-essential \
      libpq-dev \
      nodejs \
      npm \
      git \
      pkg-config \
      libxml2-dev \
      libxslt1-dev \
      liblzma-dev \
      libcurl4-openssl-dev \
      libssl-dev && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*

# Install the correct version of Bundler
RUN gem install bundler -v 2.5.23

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle update net-pop && \
    bundle install && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
    bundle exec bootsnap precompile --gemfile

# Verify the rails executable is installed
RUN bundle exec rails --version

# Copy application code
COPY . /rails

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
# Use a dummy key for precompiling, this can be set during deployment
RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile

# Final stage for app image
FROM base

# Copy built artifacts: gems, application
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
COPY --from=build /rails /rails

# Verify the rails executable is copied
RUN ls -l /rails/bin/rails

# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
    useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
    chown -R rails:rails /rails/db /rails/log /rails/storage /rails/tmp
USER rails

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start server via Thruster by default, this can be overwritten at runtime
EXPOSE 80
CMD ["bundle", "exec", "/rails/bin/rails", "server", "-b", "0.0.0.0"]
Error Summary:
The build fails at the following step in the Dockerfile:

dockerfile
Copy
Edit
RUN bundle update net-pop && \
    bundle install && \
    rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
    bundle exec bootsnap precompile --gemfile
The error message suggests that running bundle update net-pop should resolve the issue. However, when I run the Docker build command, it fails consistently with an exit code 34.

What I’ve tried: I’ve tried using the bundle update net-pop command directly and updating other gems as well. I also ensured I have the correct version of Bundler installed (version 2.5.23). Could anyone suggest how to fix this issue or if there is anything missing in my Dockerfile?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论