Skip to content

Commit ea75deb

Browse files
committed
使用多步骤构建缩减镜像大小
1 parent b2aa580 commit ea75deb

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

Dockerfile

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1-
FROM python:3.9-rc-buster
21

3-
WORKDIR /opt/url
4-
COPY . .
2+
# build stage
3+
FROM python:3.9-rc-buster as builder
54

5+
# install requirements
6+
COPY requirements.txt .
67
RUN pip install --no-cache-dir -r ./requirements.txt && \
7-
chown 1000:1000 -R /opt/url
8+
pip install --no-cache-dir pyinstaller
9+
10+
# build exec files
11+
WORKDIR /opt/src
12+
COPY . .
13+
RUN pyinstaller -D wsgi.py
814

9-
EXPOSE 9090
15+
16+
# run stage
17+
FROM python:3.9.5-slim-buster
18+
19+
WORKDIR /opt/jlu_helper
20+
COPY --from=builder /opt/src/dist/wsgi .
1021

1122
ENV SQL_USER=username
1223
ENV SQL_PASS=password
1324
ENV SQL_HOST=hostname
1425
ENV SQL_PORT=3306
1526
ENV SQL_BASE=basename
1627
ENV EXEC_TOKEN=token
28+
ENV FLASK_ENV=production
29+
30+
EXPOSE 9090
1731

18-
ENTRYPOINT [ "uwsgi", "-w", "wsgi:app", "--uid", "1000", "--http", ":9090","--master", "--workers", "3"]
32+
ENTRYPOINT [ "./wsgi"]

wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
app.register_blueprint(blueprint=api, url_prefix='/api')
1818

1919
if __name__ == "__main__":
20-
app.run()
20+
app.run(host='0.0.0.0', port=9090)

0 commit comments

Comments
 (0)