docker 常用命令:
拉取镜像:docker pull
查看镜像:docker images
容器查看:dcoker ps -a
启动容器:docker run -it /bin/bash
后台启动并映射端口、磁盘:docker run -itd -v <物理机文件地址>:<容器文件地址> -p <物理机port>:<容器port> --name <容器名> /bin/bash 注意:可以使用个-v映射多个目录
启动已停止容器:docker start
停止已启动容器:docker stop
进入容器:docker exec -it /bin/bash
删除容器:docker rm
删除镜像:docker rmi
构建镜像:docker build -t . 注意:Dockerfile放在 . 目录,也可以使用绝对路径
docker save aba01f181a4a > /opt/webconsole.tar
docker load < webconsole.tar
保存镜像:docker save -o xxx.tar <IMAGENAME:ID>
加载镜像:docker load -i xxx.tar
容器保存:docker commit 注意:容器 是启动状态,此时会生成一个新的镜像,对该镜像进行save即可保存
sudo docker run -d -it --gpus=all --net=host --name=lsh_test -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -v /data:/data1 5a14431df235 /bin/bash
docker run -d -it --gpus=all --ipc=host --name=lsh_lid1 -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -v /data:/data1 5a14431df235 /bin/bash
sudo docker run -d -it --gpus=all --net=host --name=lsh_0823_2 -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -v /data:/data1 sha256:5a14431df235bb9e0cf5f4dfebf047655e7f2760f26a8aa86ba5c44dbd10e95b /bin/bash
- docker pull ubuntu:18.04
- docker images 查看镜像
- dcoker ps -a 查看当前有哪些容器 (dcoker ps 查看当前有哪些容器是启动的)
- 创建容器 docker run -it ubuntu:18.04 /bin/bash (已经启动进入容器了)
-
创建nvidia-docker,且宿主机cuda支持docker 同时和宿主机挂载同一个路径(docker run -itd --gpus all --net=host --name csr_510 -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all -v /data4:/data1 9a2439a09348 /bin/bash)
- 如果已经创建未启动:docker start 然后进入容器(容器启动后): 进入容器:docker exec -it /bin/bash
- 更改 apt-get 下载软件镜像源:换成国内阿里云镜像源(镜像终端)
mv /etc/apt/sources.list /etc/apt/sources.list.bak
# 更改镜像为阿里镜像源
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe" >> /etc/apt/sources.list &&
echo "deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe" >> /etc/apt/sources.list
更新源:(镜像终端)
apt-get update
apt-get install wget
在镜像中下载 anaconda :(镜像终端)
# 下载 anaconda:该版本对应 python3.6
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.1.0-Linux-x86_64.sh
# 安装 anaconda
bash Anaconda3-5.1.0-Linux-x86_64.sh
此时docker 啥都没有
安装rpm
apt-get update
apt-get install rpm 这里会报错 ( Unable to correct problems, you have held broken packages )
修复步骤
1、备份原有软件源文件
cp /etc/apt/sources.list /etc/apt/sources.list.bak_yyyymmdd
2、打开sources.list文件,
在文件末尾增加如下软件源地址(任选其一)
注意,要对应自己的版本
vi /etc/apt/sources.list
- (后面有安装vim)
#添加阿里源
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 https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
3、更新
执行命令,更新系统软件源地址
sudo apt-get update
sudo apt-get upgrade #(可要可不要)
安装vim
apt-get purge vim-common
apt-get install vim
安装yum
apt-get install yum