导出依赖包
pip list --format=freeze > requirements.txt
删除 distribute, pip, setuptools, wheel 这些不必要的包
制作 Dockerfile
FROM python
ADD . /code
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_ENV='production'
ENV FLASK_RUN_HOST=0.0.0.0
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 15000
COPY . .
CMD ["flask", "run", "-p", "15000"]
构建并发布镜像
powershell:
docker buildx build --platform=linux/arm64,linux/amd64 -t jxch/capital-server:$(Get-Date -Format 'yyyyMMdd') -t jxch/capital-server:latest . --push
bash:
#!/bin/bash
sudo docker buildx build --platform=linux/arm64,linux/amd64 -t jxch/capital-ds3:$(date +%Y%m%d) -t jxch/capital-ds3:latest . --push