Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

added 3 characters in body
Source Link
wiltonsr
  • 1k
  • 9
  • 22

You can use the following example to run your flask application with uwsgi and docker.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi
[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!

You can use the following example to run your flask application with uwsgi and docker.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!

You can use the following example to run your flask application with uwsgi and docker.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!
added 15 characters in body
Source Link
wiltonsr
  • 1k
  • 9
  • 22

You can use the following example to run your flask application with uwsgi and docker.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!

You can use the following example to run your flask application with uwsgi.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!

You can use the following example to run your flask application with uwsgi and docker.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!
Source Link
wiltonsr
  • 1k
  • 9
  • 22

You can use the following example to run your flask application with uwsgi.

I will provide a minimal example and you can use it to expand to your needs.

The uwsgi conf were extracted from docs.

uwsgi.ini

[uwsgi]
shared-socket = 0.0.0.0:443
https = =0,ssl/server.crt,ssl/server.key
master = true
module = app:app
uid = uwsgi
gid = uwsgi

app.py

from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
 return "Hello, World!"
if __name__ == "__main__":
 app.run() 

requirements.txt

Flask
uWSGI==2.0.26

Dockerfile

FROM python:3.10-slim
RUN apt-get update && apt-get install -y \
 build-essential \
 gcc \
 libssl-dev \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
RUN groupadd -r uwsgi && useradd -r -g uwsgi -m uwsgi
WORKDIR /app
COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app/
COPY ssl/ /app/ssl/
RUN chown -R uwsgi:uwsgi /app
EXPOSE 443
USER uwsgi
CMD ["uwsgi", "--ini", "uwsgi.ini"]

Create an ssl directory and generate a self-signed cert.

mkdir ssl
openssl req -x509 \
 -newkey rsa:2048 \
 -keyout ssl/server.key \
 -out ssl/server.crt \
 -days 365 -nodes -subj "/CN=localhost"

Now you should have this folder structure:

.
├── app.py
├── Dockerfile
├── requirements.txt
├── ssl
│  ├── server.crt
│  └── server.key
└── uwsgi.ini

Now build and run:

docker build -t flask-uwsgi-example .
docker run --rm --name flask -p 443:443 flask-uwsgi-example

And test with curl:

$ curl -k https://localhost:443
Hello, World!
lang-py

AltStyle によって変換されたページ (->オリジナル) /