一个基于Docker的TensorRT+OpenCV项目的环境配置

最近做了个基于docker的深度学习项目,这里简要记录一下整个环境的搭建和遇到的坑,供自己以后回看和大家借鉴。

环境依赖

python 3.7.13
cuda10.2 cudnn 8.0.4
TensorRT 7.2.1.6
OpenCV 3.4.16

docker相关

由于环境依赖过于复杂,使用dockerfile直接进行部署不太现实,这里使用的是基于nvidia/cuda:10.2-cudnn8-devel-ubuntu18.04镜像进行改动,初始的dockerfile文件如下。

FROM nvidia/cuda:10.2-cudnn8-devel-ubuntu18.04

# 更新apt源
COPY sources.list /etc/apt/

# 设置入点
ENTRYPOINT ["bin/bash"]

nvidia镜像中已经安装好了cuda10.2,由于apt默认使用的国外的源进行下载和更新,这里使用了阿里云的源进行替换,只替换了前四个。

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ bionic universe
# deb-src http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates universe

cmake安装

此时docker内是没有cmake的,因此需要先完成cmake的安装,去官网https://cmake.org/download/选择版本,下载最新版就行了,以cmake-3.23.0为例,将压缩包cmake-3.23.0.tar.gz放入容器中,解压,然后

./bootstrap
make
make install

使用cmake --version进行测试
在这里插入图片描述
有类似输出就表示安装成功

python相关

创建容器,首先使用apt-get update进行更新,然后安装python的依赖项。

apt-get update
apt-get -y install build-essential python-dev python-setuptools python-pip python-smbus libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev

说实话我也不知道为啥要安装这么多的依赖项,也许有的可以不装,但我懒得试了。

然后选择你要安装的python版本,在https://www.python.org/downloads/里找到对应的压缩包,以我用的python3.7.13为例,最后下载得到了Python-3.7.13.tar.xz。
将压缩包传入docker容器中,解压,并进行安装。

mkdir -p /u
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值