diff --git a/README.md b/README.md index 60384de8..4045a07f 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,24 @@ For example, to have a maximum upload file size of 1 MB (Nginx's default) add a ENV NGINX_MAX_UPLOAD 1m ``` +### Custom listen port + +By default, the container made from this image will listen on port 80. + +To change this behavior, set the `LISTEN_PORT` environment variable. You might also need to create the respective `EXPOSE` Docker instruction. + +You can do that in your `Dockerfile`, it would look something like: + +```Dockerfile +FROM tiangolo/uwsgi-nginx-flask:python3.6 + +ENV LISTEN_PORT 8080 + +EXPOSE 8080 + +COPY ./app /app +``` + ### Custom `uwsgi.ini` file You can override where the image should look for the app `uwsgi.ini` file using the envirnoment variable `UWSGI_INI`. @@ -619,6 +637,8 @@ You will see your Flask debugging server start, you will see how it sends respon ## What's new +2017-12-08: Now you can configure which port the container should listen on, using the environment variable `LISTEN_PORT`. + 2017-09-10: Updated examples and sample project to work with SPAs even when structuring the app as a package (with subdirectories). 2017-09-02: diff --git a/python2.7/Dockerfile b/python2.7/Dockerfile index 61457d69..ab9e726e 100644 --- a/python2.7/Dockerfile +++ b/python2.7/Dockerfile @@ -9,6 +9,11 @@ RUN pip install flask # ENV NGINX_MAX_UPLOAD 1m ENV NGINX_MAX_UPLOAD 0 +# By default, Nginx listens on port 80. +# To modify this, change LISTEN_PORT environment variable. +# (in a Dockerfile or with an option for `docker run`) +ENV LISTEN_PORT 80 + # Which uWSGI .ini file should be used, to make it customizable ENV UWSGI_INI /app/uwsgi.ini diff --git a/python2.7/entrypoint.sh b/python2.7/entrypoint.sh index d3f97dd4..421bac29 100644 --- a/python2.7/entrypoint.sh +++ b/python2.7/entrypoint.sh @@ -9,17 +9,20 @@ echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.co USE_STATIC_URL=${STATIC_URL:-'/static'} # Get the absolute path of the static files from the environment variable USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} +# Get the listen port for Nginx, default to 80 +USE_LISTEN_PORT=${LISTEN_PORT:-80} # Generate Nginx config first part using the environment variables -echo 'server { +echo "server { + listen ${USE_LISTEN_PORT}; location / { - try_files $uri @app; + try_files \$uri @app; } location @app { include uwsgi_params; uwsgi_pass unix:///tmp/uwsgi.sock; } - '"location $USE_STATIC_URL { + location $USE_STATIC_URL { alias $USE_STATIC_PATH; }" > /etc/nginx/conf.d/nginx.conf diff --git a/python3.5/Dockerfile b/python3.5/Dockerfile index c2acdb2a..4b1845d6 100644 --- a/python3.5/Dockerfile +++ b/python3.5/Dockerfile @@ -9,6 +9,11 @@ RUN pip install flask # ENV NGINX_MAX_UPLOAD 1m ENV NGINX_MAX_UPLOAD 0 +# By default, Nginx listens on port 80. +# To modify this, change LISTEN_PORT environment variable. +# (in a Dockerfile or with an option for `docker run`) +ENV LISTEN_PORT 80 + # Which uWSGI .ini file should be used, to make it customizable ENV UWSGI_INI /app/uwsgi.ini diff --git a/python3.5/entrypoint.sh b/python3.5/entrypoint.sh index d3f97dd4..421bac29 100644 --- a/python3.5/entrypoint.sh +++ b/python3.5/entrypoint.sh @@ -9,17 +9,20 @@ echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.co USE_STATIC_URL=${STATIC_URL:-'/static'} # Get the absolute path of the static files from the environment variable USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} +# Get the listen port for Nginx, default to 80 +USE_LISTEN_PORT=${LISTEN_PORT:-80} # Generate Nginx config first part using the environment variables -echo 'server { +echo "server { + listen ${USE_LISTEN_PORT}; location / { - try_files $uri @app; + try_files \$uri @app; } location @app { include uwsgi_params; uwsgi_pass unix:///tmp/uwsgi.sock; } - '"location $USE_STATIC_URL { + location $USE_STATIC_URL { alias $USE_STATIC_PATH; }" > /etc/nginx/conf.d/nginx.conf diff --git a/python3.6/Dockerfile b/python3.6/Dockerfile index 835c6d55..ac9eae0d 100644 --- a/python3.6/Dockerfile +++ b/python3.6/Dockerfile @@ -9,6 +9,11 @@ RUN pip install flask # ENV NGINX_MAX_UPLOAD 1m ENV NGINX_MAX_UPLOAD 0 +# By default, Nginx listens on port 80. +# To modify this, change LISTEN_PORT environment variable. +# (in a Dockerfile or with an option for `docker run`) +ENV LISTEN_PORT 80 + # Which uWSGI .ini file should be used, to make it customizable ENV UWSGI_INI /app/uwsgi.ini diff --git a/python3.6/entrypoint.sh b/python3.6/entrypoint.sh index d3f97dd4..421bac29 100644 --- a/python3.6/entrypoint.sh +++ b/python3.6/entrypoint.sh @@ -9,17 +9,20 @@ echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.co USE_STATIC_URL=${STATIC_URL:-'/static'} # Get the absolute path of the static files from the environment variable USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} +# Get the listen port for Nginx, default to 80 +USE_LISTEN_PORT=${LISTEN_PORT:-80} # Generate Nginx config first part using the environment variables -echo 'server { +echo "server { + listen ${USE_LISTEN_PORT}; location / { - try_files $uri @app; + try_files \$uri @app; } location @app { include uwsgi_params; uwsgi_pass unix:///tmp/uwsgi.sock; } - '"location $USE_STATIC_URL { + location $USE_STATIC_URL { alias $USE_STATIC_PATH; }" > /etc/nginx/conf.d/nginx.conf