Home > front end >  Where do I put the entrypoint.sh file Rails App for Docker?
Where do I put the entrypoint.sh file Rails App for Docker?

Time:10-05

I am following this tutorial and also official Docker and they all reference an entrypoint.sh file with the contents:

#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

Do I need to create a folder usr/bin/ as referenced in the dockerfile below or /bin/bash as the comment in the entrypoint.sh file above states and place it in my root directory? I'm a bit surprised I couldn't find any details on it.

Everyone clearly states that the Dockerfile should be placed in the root directory.

# Dockerfile
FROM ruby:3.0.0
RUN apt-get update -qq && apt-get install -y postgresql-client
WORKDIR /app
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod  x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Configure the main process to run when running the image
CMD ["rails", "server", "-b", "0.0.0.0"]

Of course when I run docker build -t rails-docker . I get the error

 => ERROR [7/8] COPY entrypoint.sh /usr/bin/                                                                       0.0s
------
 > [7/8] COPY entrypoint.sh /usr/bin/:
------
failed to compute cache key: "/entrypoint.sh" not found: not found

Edit

Project Structure

> AppName
  > app
  > bin
  > config
  > db
  > lib
  > log
  > public
  > storage
  > test
  > tmp
  > vendor
- .gitfiles
- config.ru
- Dockerfile
- Gemfile
- Gemfile.lock
- Rakefile

CodePudding user response:

According to the error message, the problem is not when executing entrypoint.sh script, but when copying it. Your script is not where Docker is expecting it, or in other words, not where you told Docker it should be.

When you build image with docker image build -t <image_name> ., you're telling Docker that Dockerfile is in the current directory (.) and that the build context for the image is the current directory. That means that when you use COPY <src> <dst>, the <src> (or the source file) is relative to the build context, and the <dst> is a path inside Docker container. So, when you say COPY entrypoint.sh /usr/bin, Docker is expecting entrypoint.sh script to be located in the current directory - . from docker image build command.

  • Related