linux docker创建容器教程
目录
1.docker镜像和容器区别:
镜像是本地文件,容器是正在run运行的,需要将容器 save 或者 export 或者 commit 到本地,尽量不要覆盖原来的镜像;
2. 拉取镜像:
docker pull ***镜像
docker images
docker ps -a
docker stop Container_Name 停止容器
docker rm Container_Name 删除容器
3. 运行镜像,即->开启容器:
docker run --runtime=nvidia -v /home:/home -w /home/leilei -it --entrypoint bash -d --name cuda8.0-leilei -h pytorch0.3.1 --sym-size 32G nvidia/cuda:8.0-cudnn5.0-devel-ubuntu16.04
命令参数解析:
--runtime 运行环境,nvidia代表可以使用显卡
-v 目录映射,共享目录; /root就是用户目录,cd->pwd就可以得到
-w 工作目录,进入docker时默认的路径,但不一定是/root,直接cd,再pwd,可以看到/root
-it 进入docker之后命令行交互
--entrypoint 进入docker之后运行的命令
--name 给docker容器的命名
-h 给容器主机名hostname命名
-d 后台运行
nvidia/cuda:8.0-cudnn5.0-devel-ubuntu16.04 镜像名字(REPOSITORY:TAG)
docker start cuda8.0-leilei 开启容器
docker exec -it cuda8.0-leilei bash 进入容器 以命令行形式
4. docker内上网:
cd /root
export http_proxy=http://192.***:6666
export https_proxy=http://192.***:6666
source .bashrc
修改apt源:
编辑/etc/apt/sources.list
deb http:
//mirrors
.aliyun.com
/ubuntu/
xenial main restricted universe multiverse
deb http:
//mirrors
.aliyun.com
/ubuntu/
xenial-security main restricted universe multiverse
deb http:
//mirrors
.aliyun.com
/ubuntu/
xenial-updates main restricted universe multiverse
deb http:
//mirrors
.aliyun.com
/ubuntu/
xenial-proposed main restricted universe multiverse
deb http:
//mirrors
.aliyun.com
/ubuntu/
xenial-backports main restricted universe multiverse
deb-src http:
//mirrors
.aliyun.com
/ubuntu/
xenial main restricted universe multiverse
deb-src http:
//mirrors
.aliyun.com
/ubuntu/
xenial-security main restricted universe multiverse
deb-src http:
//mirrors
.aliyun.com
/ubuntu/
xenial-updates main restricted universe multiverse
deb-src http:
//mirrors
.aliyun.com
/ubuntu/
xenial-proposed main restricted universe multiverse
deb-src http:
//mirrors
.aliyun.com
/ubuntu/
xenial-backports main restricted universe multiverse
先rm -rf /etc/apt/sources.list.d,再
apt-get updat
5. 安装各种软件:
apt-get install vim tmux python3.5 python3-pip
rm /usr/bin/python
ln -s /usr/bin/python3.5 /usr/bin/python
查看python -V pip -V
pip install --upgrade pip
cd /usr/bin
vim pip3
将from pip import main -》 from pip import __main__
将sys.exit(main()) -》sys.exit(__main__.main())
更换pip源:cd (/root 可省); mkdir .pip ; touch pip.conf ; vim pip.conf 将下面3行复制进去
[global]
index-url = http:
//mirrors
.aliyun.com
/pypi/simple
trusted-host = mirrors.aliyun.com
LEILEI18A 发布了36 篇原创文章 · 获赞 17 · 访问量 5万+ 私信 关注