nginx: invalid option: "off" and entrypoint.sh: : Permission denied nginx: invalid option: "off" and entrypoint.sh: : Permission denied nginx nginx

nginx: invalid option: "off" and entrypoint.sh: : Permission denied


  1. Check the directory(/app) is created or not. If not use the below statement in the cfg file and give permissions to that directory
RUN mkdir -p /appRUN chmod -R 777 /app
  1. Give permissions in the entry point script also
#!/bin/shset -echmod -R 777 /appif [ "$1" = 'uat' ]; then    "$(cp /app/uat/env.js /usr/share/nginx/html && nginx -g daemon off;)"elif [ "$1" = 'prod' ]; then    "$(cp /app/prod/env.js /usr/share/nginx/html && nginx -g daemon off; )"fi
  1. For the container to spin up use an infinite loop in the entry point script and copy it to the respective location and restart the container and then can debug

Entry point script:

#!/bin/shwhile true; do sleep 120; done

Copy command:

docker cp <entry point script path> <container_name>:<path to copy the script in container>docker restart <container_name>


I spent couple of hours.last versions of nginx images requires calling /docker-entrypoint.sh

# my entrypoint# do something# do another thing#....# DON't run "exec $@" directly but run:exec /docker-entrypoint.sh $@

Do not play with CMD. keep it as the default.

imporant point: since nginx 1.19

since nginx 1.19, there are a lot of features in the default entrypoint which lets me to get rid off my custom entrypoints.

e.g: support of nginx config templates files

default.conf.template

http {  listen ${MY_PORT}}

Dockerfile

FROM nginx:1.19-alpineENV MY_PORT=80COPY default.conf.template /etc/nginx/templates/

build it then run:

docker run myimage#--> will run on 80 ( see dockerfile)docker run -e MY_PORT=8080 myimage#--> will run on 8080 ( see -e MY_PORT)

If you are curious about the logic of this feature specifically, exec to the container and check the content of this script /docker-entrypoint.d/20-envsubst-on-templates.sh

More details: