创建基于ubuntu系统并搭建python环境的docker容器

新建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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值