常用Dockerfile
# 1. python环境(Fastapi)
FROM python:3.10.13-alpine
# 设置pip源地址为阿里云镜像源
RUN python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip && \
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
pip install fastapi==0.108.0 && \
pip install "uvicorn[standard]" && \
pip install mysql_connector_repackaged==0.3.1 && \
pip install mysql-connector
# 设置工作目录
WORKDIR /app
COPY app .
ENTRYPOINT ["uvicorn","main:app","--host","0.0.0.0"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 2. nginx
Dockerfile:
# nginx镜像作为基础镜像
FROM nginx:latest
# 设置工作目录为/app
WORKDIR /app
# 删除默认的Nginx配置文件
RUN rm -rf /etc/nginx/conf.d/default.conf
# 将本地的Nginx配置文件复制到容器中
COPY default.conf /etc/nginx/conf.d
# 将本地的Web应用文件复制到工作目录
COPY ./app/app /app
# 暴露容器的80端口
EXPOSE 80
# 启动Nginx服务器
CMD ["nginx", "-g", "daemon off;"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
default.conf:
server {
listen 80;
server_name localhost; #这里可以直接添加IP
location / {
root /app;
try_files $uri $uri/ @router; #
index index.html;
}
#路由配置信息 (解决页面刷新404问题)
location @router {
rewrite ^.*$ /index.html last;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
上次更新: 2024/01/07, 07:44:52