2

I am building a Rails application on Ubuntu 18.04 and I trying to set up the deployment of the application using docker.

I have 2 entrypoint files:

  • docker/entrypoints/docker-entrypoint.sh
  • docker/entrypoints/sidekiq-entrypoint.sh

Usually, to make the files executable, I have to run the commands below in my host machine terminal:

chmod +x docker/entrypoints/docker-entrypoint.sh
chmod +x docker/entrypoints/sidekiq-entrypoint.sh

However, I would like to make this possible in the Dockerfile, without having to always do it on the host machine's terminal.

For this, I added the command below in the Dockerfile:

RUN chmod +x docker/entrypoints/docker-entrypoint.sh \
    chmod +x docker/entrypoints/sidekiq-entrypoint.sh
ENTRYPOINT ["./docker/entrypoints/docker-entrypoint.sh"]

But then I run into this error:

chmod: cannot access 'chmod': No such file or directory

chmod: cannot access '+x': No such file or directory

ERROR: Service 'app' failed to build: The command '/bin/sh -c chmod +x docker/entrypoints/docker-entrypoint.sh chmod +x docker/entrypoints/sidekiq-entrypoint.sh' returned a non-zero code: 1

I have tried a few solutions, but none has worked so far. Any form of help would be gladly appreciated.

Community
  • 1
  • 1
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
  • 3
    You need some punctuation between the two commands, `RUN chmod ... && chmod ...`. The backslash-newline inserts whitespace but doesn't actually terminate the first `chmod` command. – David Maze May 04 '20 at 11:08
  • while your solution solves the problem, there was an error in the command. It should be `chmod -x file && chmod -x another file` in your case the commands reads `chmod +x file1 chmod +x file2` since there are no chmod or +x files, it'll simply fail – Stefano May 04 '20 at 11:09
  • @Stefano, I think the command should be `chmod +x file1 chmod +x file2` and not `chmod -x file && chmod -x another file` since I am making the files executable. It will be `chmod -x file && chmod -x another file` if I am revoking the permissions for the files. – Promise Preston May 04 '20 at 11:35
  • Thank you @DavidMaze, can you elaborate more on your answer with a clearer example. – Promise Preston May 04 '20 at 11:36
  • it was a typo. I meant +x – Stefano May 04 '20 at 11:40

1 Answers1

2

Here's how I solved it:

Simply change the command in the Dockerfile from:

RUN chmod +x docker/entrypoints/docker-entrypoint.sh \
    chmod +x docker/entrypoints/sidekiq-entrypoint.sh
ENTRYPOINT ["./docker/entrypoints/docker-entrypoint.sh"]

to this:

RUN ["chmod", "+x", "/docker/entrypoints/docker-entrypoint.sh"] \
    ["chmod", "+x", "/docker/entrypoints/sidekiq-entrypoint.sh"]
ENTRYPOINT ["./docker/entrypoints/docker-entrypoint.sh"]

Also, endeavour to see that you copy/copied the docker-entrypoint.sh to your working directory. Any of the following will do it:

# Copy other project files
COPY . ./

# Docker init
RUN ["chmod", "+x", "docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]

OR

# Copy docker entrypoint file
COPY docker-entrypoint.sh ./

# Docker init
RUN ["chmod", "+x", "docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]

OR

# Copy docker entrypoint file
COPY /docker/docker-entrypoint.sh ./docker/docker-entrypoint.sh

# Docker init
RUN ["chmod", "+x", "docker/docker-entrypoint.sh"]
ENTRYPOINT ["./docker/docker-entrypoint.sh"]

Note: This depends on the location of your docker-entrypoint.sh and where you was to copy it to.

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143