- pip freeze > requirements.txt
- 编写dockerfile,需要注意的是这里安装了一些c++库文件供opencv使用
Dockerfile:
FROM python:3.9-slim # 将工作目录设置为 当前目录 WORKDIR /opt/app/ # 将当前目录内容复制到容器中 ADD . /opt/app/ RUN apt-get update RUN apt install -y g++ RUN apt install -y cmake RUN apt install -y make RUN apt install -y wget unzip RUN apt-get -y install build-essential libgtk2.0-dev libgtk-3-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev # 安装 requirements.txt 中指定的任何所需软件包 RUN pip install -r requirements.txt # 在容器启动时运行 main.py CMD ["python", "main.py"] #CMD ["python","./apps/min.py","worker","-l","info"] ##faust程序worker启动命令
FROM python:3.9-slim MAINTAINER Sea <sealiu@icil.net> VOLUME /tmp RUN mkdir -p /opt/app/ RUN chmod -R 777 /opt/app/ #RUN rm -rf /usr/local/lib/python3.9/site-packages/ #COPY site-packages /usr/local/lib/python3.9 COPY . /opt/app/ RUN pip install --default-timeout=1000 --no-cache-dir -r /opt/app/requirements.txt WORKDIR /opt ENTRYPOINT [ "sh", "-c", "python3 /opt/app/SeaKaflaListener.py" ]
- docker根据Dockerfile构建镜像: docker build -f Dockerfile -t seatest:1.1 .