linux docker创建容器教程

                                                                        linux docker创建容器教程

目录

1.docker镜像和容器区别:

2. 拉取镜像:

3. 运行镜像,即->开启容器:

4. docker内上网:

5. 安装各种软件:

6. 解决cv2的问题:

7. 设置python版本:


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 --shm-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 进入容器 以命令行形式

docker stop 容器名 关闭容器

docker rm 容器名 删除容器

4. docker内上网:

cd /root

修改.bashrc,添加环境变量

若是不知道ip,win下面cmd ipconfig,无线局域网适配器 WLAN IPV4地址

export http_proxy=http://<your_ip>: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 update

5. 安装各种软件:

apt-get install vim tmux python3.5 python3-pip

pip3 install --upgrade pip

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

6. 解决cv2的问题:

apt-get install libglib2.0-dev

# 安装apt-file

apt-get install apt-file

# 更新

apt-file update

# 寻找依赖

apt-file search libSM.so.6

# 安装依赖

apt-get install libsm6

apt-get install libxrender1

或者:

apt install python-qt4

将pillow版本降到7以下

7. 设置python版本:

将python默认成python3.5

rm /usr/bin/python

ln -s /usr/bin/python3.5 /usr/bin/python

查看python -V        pip -V

 

 

 

 

 

 

 

发布了36 篇原创文章 · 获赞 17 · 访问量 5万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章