Running a bash script before startup in an NGINX docker container

后端 未结 5 829
野性不改
野性不改 2021-02-15 10:56

I\'m trying to run a javascript app on localhost:8000 using docker. Part of what I would like to do is swap out some config files based on the docker run command, I\'d like to p

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-15 11:41

    Update the CMD line as below in the your dockerfile. Please note that if runfile.sh does not succeed (exit 0; inside it) then the next nginx command will not be executed.

    FROM nginx
    COPY . /usr/share/nginx/html
    CMD /usr/share/nginx/html/runfile.sh && nginx -g 'daemon off;'
    

    nginx docker file is using a CMD commnd to start the server on the base image you use. When you use the CMD command in your dockerfile you overwrite the one in their image. As it is mentioned in the dockerfile documentation:

    There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

提交回复
热议问题