目录
配置流程视频链接:here
一.docker环境配置
1.1下载安装docker(linux)
1.2Docker 镜像下载
1.3创建 docker 容器
二.在容器中配置ssh
2.1在容器中配置ssh
2.2测试ssh root 用户登录
2.21 常见问题
三.配置pycharm
2.2配置远程解释器编辑
yolov7代码运行测试
编辑
(重要)docker以及nvidia-container-toolkit配置:用时调用宿主机gpu
(忽略)docker安装官方文档
(忽略)native-container-toolkit配置官方文档
Docker Hub
或者命令行搜索:(找不全)
docker search yolov7 --filter=STARS=100 过滤星数100以下的镜像
docker search yolov7 --filter=STARS=100
拉取 docker 镜像
docker pull ainavy/yolov7
查看镜像
docker run --name aiyolov7 -it -v /home/tuolong/project/aiyolov7:/yolov7 -v /home/tuolong/project/dataset_aiyolo:/dataset -p 10022:22 --gpus all --ipc=host fe1c0c11f804
docker run
# 参数说明
--name #容器名字:用来区分容器,一个镜像能建立多不同容器
-it #使用交互式运行:进入容器查看内容
-v #挂载卷
#-v /home/tuolong/project/aiyolov7:/yolov7 宿主机yolov7代码地址:容器内yolov7地址
#-v /home/tuolong/project/dataset_aiyolo:/dataset 主机数据集地址:容器数据集地址
-p #宿主机端口:容器内部端口
--gpus #要添加到容器中的gpu设备(all用于传递所有gpu)
--ipc #ipc=host表示主机与docker共享所有内存空间
#fe1c0c11f804 镜像id
创建成功:
tuolong@tuolong-20:~$ docker run --name aiyolov7 -it -v /home/tuolong/project/aiyolov7:/yolov7 -v /home/tuolong/project/dataset_aiyolo:/dataset -p 6666:8888 --gpus all --ipc=host fe1c0c11f804
=============
== PyTorch ==
=============
NVIDIA Release 21.08 (build 26011915)
PyTorch Version 1.10.0a0+3fd9dcf
Container image Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
Copyright (c) 2014-2021 Facebook Inc.
Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
Copyright (c) 2011-2013 NYU (Clement Farabet)
Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
Copyright (c) 2015 Google Inc.
Copyright (c) 2015 Yangqing Jia
Copyright (c) 2013-2016 The Caffe contributors
All rights reserved.
NVIDIA Deep Learning Profiler (dlprof) Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
Various files include modifications (c) NVIDIA CORPORATION. All rights reserved.
This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:
https://developer.nvidia.com/ngc/nvidia-deep-learning-container-license
NOTE: MOFED driver for multi-node communication was not detected.
Multi-node communication performance may be reduced.
root@afd1f53c7a34:/home/navy# nvidia-smi
Mon Nov 21 08:29:27 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.85.02 Driver Version: 510.85.02 CUDA Version: 11.6 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | N/A |
| N/A 41C P8 1W / N/A | 5MiB / 6144MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
root@afd1f53c7a34:/home/navy#
注意:
可能存在的问题:
docker 重装可能遇到的问题:
:~$ sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://mirrors.ustc.edu.cn/ros/ubuntu focal InRelease
Hit:4 http://kr.archive.ubuntu.com/ubuntu focal InRelease
Hit:5 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu focal InRelease
Hit:6 http://kr.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:7 https://librealsense.intel.com/Debian/apt-repo focal InRelease
Hit:8 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:9 http://kr.archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
W: Target Packages (stable/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11 (stable/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11 (stable/dep11/Components-all.yml) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11-icons-small (stable/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11-icons (stable/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11-icons-hidpi (stable/dep11/[email protected]) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11 (stable/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11 (stable/dep11/Components-all.yml) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11-icons-small (stable/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11-icons (stable/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target DEP-11-icons-hidpi (stable/dep11/[email protected]) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:60 and /etc/apt/sources.list.d/docker.list:1
解决方案:
https://blog.csdn.net/TUOLONGcsdn/article/details/128017828?spm=1001.2014.3001.5502
参考:pycharm使用docker环境调试的配置步骤
root@afd1f53c7a34:~# apt update
root@afd1f53c7a34:~# mkdir /var/run/sshd
root@afd1f53c7a34:~# echo 'root:123' | chpasswd
root@afd1f53c7a34:~# sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
root@afd1f53c7a34:~# sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
root@afd1f53c7a34:~# echo "export VISIBLE=now" >> /etc/profile
root@afd1f53c7a34:~# service ssh restart
root@afd1f53c7a34:~# exit
exit
tuolong@tuolong-20:~$ docker ps #查看正在运行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
tuolong@tuolong-20:~$ docker ps -a #查看全部容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
afd1f53c7a34 fe1c0c11f804 "/usr/local/bin/nvid…" 3 hours ago Exited (0) 40 seconds ago aiyolov7
tuolong@tuolong-20:~$ docker start afd1f53c7a34 #开启容器
afd1f53c7a34
tuolong@tuolong-20:~$ sudo docker port afd1f53c7a34 8888
#或者直接输入 sudo docker port +(容器id)
#afd1f53c7a34 容器id 8888 端口号
#若配置生效则会输出如下
0.0.0.0:6666
:::6666
ssh root@[主机ip] -p 22 #注意这里为docker容器内的主机ip
查询docker内主机ip
hostname -i
ssh root用户远程登录问题
tuolong@tuolong-20:~$ ssh [email protected] -p 22
[email protected]'s password:
Permission denied, please try again.
[email protected]'s password:
Permission denied, please try again.
[email protected]'s password:
[email protected]: Permission denied (publickey,password).
解决方案:
查看/etc/ssh/sshd_config配置,将服务端PermitRootLogin 后缀改为yes.允许远程root登录
参考:SSH连接报错:Permission denied, please try again.的解决方法
tuolong@tuolong-20:~$ docker exec -it 40e689292913 /bin/bash
root@40e689292913:/home/navy# vim /etc/ssh/sshd_config
将PermitRootLogin 参数改为yesservice ssh restart
注意项目地址选择创建docker容器时给定的数据同步文件夹。
这样才能将代码运行结果同步到本地。