Closed simoniong closed 1 month ago
Can you share a dockefile that reproduce the issue?
File.executable?
is riddled with issues, so we might want to stop using it and just try running something like node --version
or whatever.
This is the Dockerfile
FROM ruby:2.7.8-alpine as builder
ARG SSH_PRIVATE_KEY
RUN apk add --no-cache git openssh-client tzdata postgresql-dev
RUN apk add --no-cache nodejs yarn build-base shared-mime-info gcompat
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
WORKDIR /app
ENV RAILS_ENV=production
ENV NODE_ENV=production
COPY Gemfile Gemfile.lock /app/
RUN gem install bundler:1.17.2
RUN gem install nokogiri:1.13.10
RUN --mount=type=ssh bundle install --jobs 4 --without development:test --deployment
# COPY package.json yarn.lock /app/
COPY yarn.lock /app/
RUN yarn install
COPY . /app/
RUN --mount=type=ssh bin/rails assets:precompile aws_access_key=xxx aws_secret_key=yyy aws_bucket=bubu secret_key_base=xxx
##############################################################
FROM ruby:2.7.8-alpine
RUN apk add --no-cache bash tzdata postgresql-dev file imagemagick nodejs shared-mime-info gcompat && \
cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
ENV RAILS_ENV=production
WORKDIR /app
COPY . /app/
COPY --from=builder /usr/local/bundle/config /usr/local/bundle/config
COPY --from=builder /app/vendor/bundle/ /app/vendor/bundle/
COPY --from=builder /app/public/ /app/public/
RUN gem install bundler:1.17.2
EXPOSE 3000
CMD ["bin/rails", "server"]
I'm not able to reproduce, I reduced your Dockefile to just:
FROM ruby:2.7.8-alpine as builder
RUN apk add --no-cache git openssh-client tzdata postgresql-dev
RUN apk add --no-cache nodejs yarn build-base shared-mime-info gcompat
# WORKDIR /app
#
# ENV RAILS_ENV=production
# ENV NODE_ENV=production
#
# COPY Gemfile Gemfile.lock /app/
# RUN gem install bundler:1.17.2
# RUN gem install nokogiri:1.13.10
# RUN --mount=type=ssh bundle install --jobs 4 --without development:test --deployment
#
# # COPY package.json yarn.lock /app/
# COPY yarn.lock /app/
# RUN yarn install
#
# COPY . /app/
#
# RUN --mount=type=ssh bin/rails assets:precompile aws_access_key=xxx aws_secret_key=yyy aws_bucket=bubu secret_key_base=xxx
# ##############################################################
FROM ruby:2.7.8-alpine
RUN apk add --no-cache bash tzdata postgresql-dev file imagemagick nodejs shared-mime-info gcompat && \
cp /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
# ENV RAILS_ENV=production
# WORKDIR /app
# COPY . /app/
# COPY --from=builder /usr/local/bundle/config /usr/local/bundle/config
# COPY --from=builder /app/vendor/bundle/ /app/vendor/bundle/
# COPY --from=builder /app/public/ /app/public/
# RUN gem install bundler:1.17.2
#
# EXPOSE 3000
# CMD ["bin/rails", "server"]
And node is seen as executable:
>> File.executable? '/usr/bin/node'
=> true
It's weird, while I try to build it from my MacBookPro, and run it within my MacBookPro, the result is the same as yours, and I could use irb.
> docker run -it d7e62f6e54d3 bash
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
> irb
irb(main):001:0> File.executable? '/usr/bin/node'
=> true
irb(main):002:0> File.executable? 'node'
=> false
irb(main):003:0>
> ruby -e "p File.executable? '/usr/bin/node'"
true
> docker -v
Docker version 27.2.0, build 3ab4256
but while I try to remote access(ssh) to my VPS, use the same images, I can't really run irb at all.
> docker exec -it 948aa4879c72 bash
> irb
Traceback (most recent call last):
6: from /usr/local/bin/irb:23:in `<main>'
5: from /usr/local/bin/irb:23:in `load'
4: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
3: from /usr/local/lib/ruby/2.7.0/irb.rb:393:in `start'
2: from /usr/local/lib/ruby/2.7.0/irb/init.rb:18:in `setup'
1: from /usr/local/lib/ruby/2.7.0/irb/init.rb:121:in `init_error'
/usr/local/lib/ruby/2.7.0/irb/locale.rb:121:in `load': No such file to load -- irb/error.rb (LoadError)
> ruby -e "p File.executable? '/usr/bin/node'"
false
> docker -v
Docker version 19.03.8, build afacb8b7f0
It seems the root cause to be my docker version too low, and after upgrade to latest one, it is okay now.
Docker container env & softwares I install:
execjs is latest version 2.9.1, and while i kick start rails, I got this error:
I have no idea why Node can't interprited as a executable. can anyone help?