Running a bash script before startup in an NGINX docker container

后端 未结 5 840
野性不改
野性不改 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:47

    I know this is late but I found this thread while searching for a solution so thought I'd share.

    I had the same issue. Your ENTRYPOINT script should also include exec "$@"

    #!/bin/sh
    set -e
    envsubst '\$CORS_HOST \$UPSTREAM_CONTAINER \$UPSTREAM_PORT' < /srv/api/default.conf > /etc/nginx/conf.d/default.conf
    exec "$@"
    

    That will mean the startup CMD from the nginx:alpine container will run. The above script will inject the specified environment variables into a config file. By doing this in runtime yo can override the environment variables.

提交回复
热议问题