0

In Debian GNU/Linux 11 (bullseye) based Dockerfile, I tried to use CMD to run an entry point command:

#EDIT

WORKDIR "/tmp"

USER root

COPY ./entrypoint.sh /tmp/rails/entrypoint.sh
RUN chmod +x /tmp/rails/entrypoint.sh
EXPOSE 80
CMD ["/bin/bash","-c","/tmp/rails/entrypoint.sh"]

/tmp/rails/entrypoint.sh:

#!/bin/bash
nginx -g 'daemon off;'
cd /tmp
RAILS_ENV=proudction bundle exec rails server -p 3000
service nginx start

But I still getting error

/bin/bash: 1: ./entrypoint.sh: not found

I also tried

ENTRYPOINT /tmp/rails/entrypoint.sh
CMD ["/bin/bash","-c","/tmp/rails/entrypoint.sh"]

but it always show entrypoint.sh not found, Any idea?

EDIT

full docker file:

FROM ruby:3.0.5

RUN apt update -y
RUN apt install -y nginx
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.6.1 /lambda-adapter /opt/extensions/lambda-adapter

RUN apt-get update -y
RUN apt-get --assume-yes install autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev



RUN apt-get install -y rubygems #ruby-dev
RUN gem install bundler -v '2.2.32'
RUN bundle config --local build.sassc --disable-march-tune-native

# UPDATE NODE:
RUN curl -sL https://deb.nodesource.com/setup_12.x |  bash -
RUN apt-get install -y nodejs
# YARN:
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt update && apt install yarn
# Fix issue with sassc gem
RUN bundle config --local build.sassc --disable-march-tune-native
RUN apt-get install -y awscli
#END OF ORIGINAL

#RUN bundle config set without 'development test'

#RUN rm -rf /home/app/webapp/app
RUN mkdir /tmp/rails
COPY . /tmp/rails
WORKDIR "/tmp/rails"



RUN bundle install # --path=vendor
ENV RAILS_SERVE_STATIC_FILES false

ENV EXECJS_RUNTIME=Disabled
ENV WEBPACKER_PRECOMPILE=false
ENV NODE_ENV=production

RUN yarn config set ignore-engines true
#RUN bundle exec rails webpacker:compile
RUN bundle exec rails assets:precompile

ARG GIT_REVISION_ARG
ENV GIT_REVISION=$GIT_REVISION_ARG

#Rails App
RUN rm -f /etc/service/nginx/down
RUN rm -f /etc/nginx/sites-enabled/default
ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf

RUN chmod +x /tmp/rails/entrypoint.sh

WORKDIR "/tmp"

ADD nginx/app/config/ /etc/nginx/
ADD nginx/app/images/ /usr/share/nginx/html/images
USER root

COPY ./entrypoint.sh /tmp/rails/entrypoint.sh
RUN chmod +x /tmp/rails/entrypoint.sh

ENTRYPOINT /tmp/rails/entrypoint.sh
EXPOSE 80

CMD ["/bin/bash","-c","/tmp/rails/entrypoint.sh"]

simo
  • 23,342
  • 38
  • 121
  • 218
  • 2
    Are you sure `./entrypoint.sh` exists when doing the `COPY` ? – 0stone0 Jan 30 '23 at 12:16
  • 1
    The code you show explicitly runs `/tmp/rails/entrypoint.sh`; where is the `./entrypoint.sh` syntax used? What is the container's `WORKDIR`? (Do you need separate containers to run the Rails application and Nginx reverse proxy?) – David Maze Jan 30 '23 at 12:20
  • @0stone0 yes, entrypoint.sh is in the same folder that has Dockerfile @DavidMaze @0stone0 kindly check EDIT above, working directory is `/tmp` I don't need separate containers, its only one container. – simo Jan 30 '23 at 12:31
  • This doesn't look like a complete Dockerfile. Is there an `ENTRYPOINT` directive in this Dockerfile, or in the base image you're using? – larsks Jan 30 '23 at 12:33
  • oh, it could be in the base image, let me check, I am sure the base image has no CMD though – simo Jan 30 '23 at 12:34
  • per Docker documentation, only the last `ENTRYPOINT` should be effective. – simo Jan 30 '23 at 12:38
  • @larsks I've just added the dockerfile, kindly check, the error `/bin/bash: 1: /tmp/rails/entrypoint.sh: not found` – simo Jan 30 '23 at 12:53
  • `/tmp` is by definition temporary. You should consider installing your files in another location, like `/usr/local`. – BMitch Jan 30 '23 at 13:14
  • I can't reproduce that error with your Dockerfile. Can you include in your question the exact commands you're using to (a) build the image and then (b) start a container using that image? – larsks Jan 30 '23 at 13:21
  • I am running the container inside AWS Lambda env, https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html I used tmp folder as its the only writable folder at lambda env while running the container. – simo Jan 30 '23 at 13:46
  • Your last WORKDIR is /tmp not /tmp/rails where entrypoint.sh is – Rakesh Gupta Jan 30 '23 at 13:52
  • Yes, but I am using the full path to execute `/tmp/rails/entrypoint.sh` – simo Jan 30 '23 at 13:59
  • You are running a container, you should be able to put your entrypoint somewhere else at build time. You're image layers are read only. – Julien B. Jan 30 '23 at 15:03

0 Answers0