当前位置:   article > 正文

docker简易使用_opencv docker

opencv docker

安装

可参考官网:https://www.docker.com/
docker nvidia hub:https://hub.docker.com/r/nvidia/cuda/tags/?page=1&name=10.1

nvidia docker官网docker镜像https://catalog.ngc.nvidia.com/containers

NVIDIA-NX等边缘设备docker镜像https://catalog.ngc.nvidia.com/orgs/nvidia/containers/l4t-jetpack

如果需要对cuda向下兼容,需要下载以下镜像
https://catalog.ngc.nvidia.com/orgs/nvidia/collections/nvidia_dlfw/entities

# 执行拉取命令
docker pull nvidia/cuda:10.1-devel-centos7
# 使用命令我们可以看到已有的镜像
docker images
 sudo docker run -it -p 6739:9010 nvidia/cuda:10.1-devel-ubuntu18.04 /bin/bash

# 需要带上参数  --runtime=nvidia
docker run --restart=on-failure --runtime=nvidia --network host  -it nvidia/cuda:10.1-devel-centos7 /usr/bin/sh
# 使用命令
nvidia-smi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

运行docker 镜像: docker run -it ubuntu:latest /bin/bash
在这里插入图片描述
重启docker 容器(sudo docker exec -it a0974e7e4b40 /bin/bash)
a0974e7e4b40 为运行中的ID
挂载目录

sudo docker run -itd -v /home/kevin/src:/home/dst 容器name /bin/bash
  • 1

查看ID:docker inspect -f ‘{{.Id}}’ ubuntu,用于cp文件。

保存镜像,docker commit 0bd244689ed2 ubuntu-vim,其中0bd244689ed2 为运行状态的ID
在运行状态下:执行docker cp

删除none的镜像,要先删除镜像中的容器。要删除镜像中的容器,必须先停止容器。

$ docker images

$ docker rmi $(docker images | grep "none" | awk '{print $3}')
直接删除带none的镜像,直接报错了。提示先停止容器。

$ docker stop $(docker ps -a | grep "Exited" | awk '{print $1 }') //停止容器

$ docker rm $(docker ps -a | grep "Exited" | awk '{print $1 }') //删除容器

$ docker rmi $(docker images | grep "none" | awk '{print $3}') //删除镜像
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
 docker cp NVIDIA-Linux-x86_64-440.64.run eb4fd0a987f3:/home/nvrun.run
  • 1

安装显卡驱动,apt-get install nvidia-driver-440

docker镜像导出与离线安装

#docker save -o [文件名] [镜像名]
#示例
docker save -o nacos-server.docker nacos/nacos-server:1.3.2

  • 1
  • 2
  • 3
  • 4
#docker load -i [文件名]
#示例
docker load -i nacos-server.docker

  • 1
  • 2
  • 3
  • 4

docker常用命令

在这里插入图片描述

# 构建镜像指令
docker build -t nvidia_cuda11_centos7_python3.8 .
.
# 进入镜像指令
docker exec -it 86c26cdaea16 /bin/bash
# 进把容器构建为镜像指令
docker commit -a leowen -m "nvidia cuda 11 python 3.8" 86c26cdaea16 nvidia-cuda-python:ubuntu20-cuda11-cudnn8-python3.8

# cpu下启动镜像
docker run -d -v /home/data:/home/data:rw --name imagesave -p 9005:80 imagesave
docker run -d -v /home/data:/home/data:rw --name tfmodel -p 9006:80 tfmodel
docker run -d --add-host=host.docker.internal:host-gateway -v /home/data:/home/data:rw --name tfmodel -p 9006:9006 tfmodel
docker run -d --add-host=host.docker.internal:host-gateway -v /home/data:/home/data:rw --name tfmodel_grpc -p 9007:9006 tfmodel_grpc
docker run -dt -v /nginx/html:/usr/share/nginx/html --name nginx nginx
docker run -dt -v /nginx/html:/usr/share/nginx/html:ro --name nginx nginxdocker
docker run -d  --name tfmodel -p 9006:80 tfmodel
# gpu下启动镜像
nvidia-docker run -d  --gpus "device=0" --name yolo_gpu -p 9006:80 cuda_nv_yolo
nvidia-docker run -it  --gpus "device=0" --name cuda11_python nvidia_cuda11_centos7_python3.8:latest
nvidia-docker run -it  --gpus "device=0" --name cuda11_ubuntu nvidia/cuda:11.2.0-cudnn8-devel-ubuntu20.04
nvidia-docker run -it  --gpus "device=0" --name cuda_test -p 9001:80 cuda_test
# 查看容器日志
docker logs tfmodel

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

批量构建docker

docker build -f dockfiles/normal/Dockerfile -t normal:22.10.09 .
  • 1

删除opencv

1. $ sudo make uninstall
2. $ cd ..
3. $ sudo rm -r build
4. $ sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
  • 1
  • 2
  • 3
  • 4
5. sudo apt-get –purge remove opencv-doc opencv-data python-opencv
  • 1
pkg-config opencv --libs
pkg-config opencv --modversion
  • 1
  • 2
cd opencv-3.4.5
 
cd build
sudo make uninstall
cd ..
 
sudo rm -rf build
sudo rm -r \
/usr/local/include/opencv\
/usr/local/include/opencv2 \
/usr/include/opencv \
/usr/include/opencv2 \
/usr/local/bin/opencv* \
/usr/local/lib/libopencv* \
/usr/local/share/opencv \
/usr/local/share/OpenCV \
/usr/share/opencv \
/usr/share/OpenCV
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
make uninstall
cd ..
sudo rm -r build
sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
  • 1
  • 2
  • 3
  • 4

参考文章:

  • https://www.runoob.com/docker/docker-dockerfile.html
  • 驱动安装https://blog.csdn.net/qq_33547243/article/details/107433616
  • docker复制文件https://www.jb51.net/article/157169.htm
  • https://www.cnblogs.com/blacksmith4/p/13493568.html
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/108011
推荐阅读
相关标签
  

闽ICP备14008679号