Will the application run as PID 1 and will signals be received if we bootstrap it in a entrypoint.sh?

前端 未结 2 1003
没有蜡笔的小新
没有蜡笔的小新 2021-01-20 18:37

It\'s good practice to start the service with

CMD [\"/go/bin/myapp\"]

instead of

CMD /go/bin/myapp

In the

2条回答
  •  孤街浪徒
    2021-01-20 19:18

    Here is my try to follow what also the MySQL 5.7 Dockerfile does... but with an Nginx image.

    Dockerfile:

    FROM nginx:latest
    COPY docker-entrypoint.sh /usr/local/bin/
    RUN chmod 777 /usr/local/bin/docker-entrypoint.sh
    
    ENTRYPOINT ["docker-entrypoint.sh"] 
    EXPOSE 80
    CMD ["nginx", "-g", "daemon off;"]
    

    docker-entrypoint.sh:

    #!/bin/bash
    set -e
    
    echo "preparing..."
    
    exec "$@"
    

    The idea is to do anything needed as a preparation inside the docker-entrypoint.sh script and with exec "$@" you then pass the signals to the CMD. (This means that you will have to use envsubst < /etc/nginx/conf.d/site.template > /etc/nginx/conf.d/default.conf inside docker-entrypoint.sh)


    Link of relevant example to Dockerfile docs: If you need to write a starter script for a single executable, you can ensure that the final executable receives the Unix signals by using exec and gosu commands...

提交回复
热议问题