新建requirements.txt
flask==2.0.2
新建doc/sources.list文件 ,写入ubuntu源配置
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
新建Dokcerfile文件
FROM ubuntu:18.04
# 设置时区运行参数
ARG DEBIAN_FRONTEND=noninteractive
# 设置时区环境
ENV TZ=Asia/Shanghai
ADD . /code
WORKDIR /code
COPY requirements.txt /code/
COPY doc/sources.list /etc/apt/sources.list
RUN apt-get clean
&& apt-get update
&& apt-get install -y --assume-yes apt-utils
&& apt-get install -y python3-opencv
&& apt-get install -y plastimatch
&& apt-get install -y python-gdcm
&& apt-get install -y libgdcm-tools
&& apt-get install -y tzdata
&& apt-get install -y sudo
&& apt-get install -y python3.6
&& apt-get install -y python3-pip
&& apt-get install -y git
&& ln -s /usr/bin/pip3 /usr/bin/pip
&& pip3 --default-timeout=1000 install -U pip
&& pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple
&& pip3 config set install.trusted-host mirrors.aliyun.com
&& pip3 install -r requirements.txt
&& pip3 install -U setuptools
新建docker-compose.yml
# compose 版本为3.8
version: "3.8"
services:
web:
container_name: demo
image: "demo:v1.0"
build:
context: .
dockerfile: Dockerfile
command:
- /bin/bash
- -c
- |
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
export TZ=Asia/Shanghai
cd /code
pip3 install --upgrade pip
pip3 install -r requirements.txt
python3 starter.py
ports:
- "9005:9005"
privileged: true
tty: true
stdin_open: true
启动容器
docker-compose up -d