Search code examples
ruby-on-railsbashdocker

Docker Rails entrypoint.sh failure


I`m trying to create a docker with rails project:

Here`s my dockerfile:

FROM ruby:3.1.2-slim

RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
    build-essential \
    gnupg2 \
    less \
    git \
    libpq-dev \
    postgresql-client \
    libvips42 \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV LANG=C.UTF-8 \
  BUNDLE_JOBS=4 \
  BUNDLE_RETRY=3

RUN gem update --system && gem install bundler

WORKDIR /usr/src/app

ENTRYPOINT ["sh", "./entrypoint.sh"]

EXPOSE 3001

CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]

And here is my entrypoint.sh

#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /usr/src/app/tmp/pids/server.pid

echo "bundle install..."
bundle check || bundle install --jobs 4

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

I`ve also added the rights permissions

-rwxr-xr-x   1 vitat  staff   274 22 Mar 16:02 entrypoint.sh

When I run: docker-compose up -d I got this error:

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./entrypoint.sh": stat ./entrypoint.sh: no such file or directory: unknown

What I doing wrong?


Solution

  • Just as the error says, Docker is unable to find entrypoint.sh at the path ./entrypoint.sh when trying to start your container. The most likely cause is that the entrypoint.sh script is not where Docker expects it to be when the ENTRYPOINT instruction is executed.

    So ensure it’s in the same directory as your Dockerfile and included in your Docker image. Try making the following changes to your Dockerfile:

    WORKDIR /usr/src/app
    
    # Copy the entrypoint script into the container at /usr/src/app
    COPY entrypoint.sh /usr/src/app/
    RUN chmod +x /usr/src/app/entrypoint.sh
    
    ENTRYPOINT ["sh", "./entrypoint.sh"]
    

    Make sure to rebuild your Docker image with docker-compose build after making these changes, before running docker-compose up -d again.