Flask之使用gunicorn和docker部署项目
程序员文章站
2022-04-21 23:30:04
...
1. 目录结构:
2. gunicorn_config.py:
bind = "0.0.0.0:5000"
workers = 3
timeout = 300
3. Dockerfile:
FROM python:3.6
MAINTAINER Quincy Cui <quincycui@tcl.com>
RUN pip install gunicorn
COPY . /src/
WORKDIR /src
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["gunicorn", "--config", "/src/gunicorn_config.py", "app:app"]
4.相关部署命令:
4.1
docker build . -t seclab_himusic_admin_backend:Release-v1.0
4.2
docker run -d \
-p 9006:5000 \
–name seclab_himusic_admin_backend \
-e AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY \
-e AWS_DEFAULT_REGION=us-east-1 \
–restart=always seclab_himusic_admin_backend:Release-v1.0
4.3相关说明:
#使用外部传参方式os.getenv获取数据库密码,保证安全
__dynamodb = boto3.resource('dynamodb',
region_name=os.getenv("AWS_DEFAULT_REGION"),
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"))
查看docker可用的ip:
docker inspect $(docker ps -q) | grep IPAddress
上一篇: 使用 Capsitrano 部署 Sinatra 项目
下一篇: C++练习(七)多态性与虚函数