STC214/python程序制作成docker镜像之后体积过大如何精简

Created Fri, 19 Feb 2021 17:11:15 +0800 Modified Fri, 19 Feb 2021 17:11:15 +0800

1.找到对应版本的docker镜像

2.在对应的镜像下找到体积最理想的标签

3.编写Dockerfile,模板如下


# Use an official Python runtime as a parent image
FROM python:3.7.10-alpine3.13

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME daily189

# Run app.py when the container launches
CMD ["python", "Run_all_schedule.py"]

之后进行build就可以有效减少docker文件的体积了