AnDev123
AnDev123

Reputation: 519

Docker File: Chmod on Entrypoint Script

Is there a reason I need to chmod +x on my entrypoint script? It didn't appear Redis was doing this in their dockerfile (https://github.com/docker-library/redis/blob/109323988b7663bceaf4a01c3353f8934dfc002e/2.8/Dockerfile) for their entrypoint script.

Dockerfile:

# Generic Docker Image for Running Node app from Git Repository
FROM    node:0.10.33-slim
ENV NODE_ENV production

# Add script to pull Node app from Git and run the app
COPY docker-node-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE  8080
CMD ["--help"]

Upvotes: 29

Views: 69766

Answers (3)

alsator
alsator

Reputation: 121

Try this way

RUN ["chmod", "+x", "/entrypoint.sh"]

it have worked for me

Upvotes: 0

BMitch
BMitch

Reputation: 263746

Docker will copy files into the container with the permissions of their source. If you strip the Linux executable bits somewhere in the chain of pushing to your code repo, or on your build host, then you'll need to add those execute permissions back. I've seen this issue most often reported by Windows users, who are downloading code to a filesystem that doesn't support the Linux permission bits. Hopefully we'll get a COPY --chmod solution soon that will eliminate the need for an extra layer.

Upvotes: 17

ISanych
ISanych

Reputation: 22680

redis don't need to do it because their script already have exec flag:

~/redis/2.8$ ls -l docker-entrypoint.sh 
-rwxrwxr-x 1 igor igor 109 Dec  3 23:52 docker-entrypoint.sh

if you will do it for your docker-node-entrypoint.sh script you would not need chmod in Dockerfile too.

This is possible because the git core.fileMode option by default is true, so the executable bit of a file is honored.

Upvotes: 16

Related Questions