Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make listen port configurable #27

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions python2.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions python2.7/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions python3.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions python3.5/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions python3.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions python3.6/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down