1 系统与Docker基础配置
- Ubuntu18.04
1.0 卸载Docker旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc
1.0 更新系统仓库
sudo apt-get update
1.2 安装docker仓库源
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
1.3 添加认证
国内仓库源:推荐
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
官方源:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
1.4 设置稳定源
国内源:推荐
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
官方源:
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
1.5 添加国内仓库源
安装vim
sudo apt-get install vim
打开源文件
sudo vim /etc/apt/sources.list
编辑:
i
添加源路径
deb http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main multiverse restricted universe
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main multiverse restricted universe
退出编辑模式:
esc
保存命令(注意有冒号):
:wq
r退出:
回车Enter
2 安装Docker
2.1 查看可以用版本
apt-cache madison docker-ce
- 清单
docker-ce | 5:18.09.4~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 5:18.09.3~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
...
docker-ce | 18.06.3~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
...
docker-ce | 18.03.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 18.03.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
2.2 安装指定版本
命令格式
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
指定18.03.0版本
sudo apt-get install docker-ce=18.03.0~ce-0~ubuntu
运行结果
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
aufs-tools cgroupfs-mount git git-man liberror-perl pigz
Suggested packages:
git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk
gitweb git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
aufs-tools cgroupfs-mount docker-ce git git-man liberror-perl pigz
0 upgraded, 7 newly installed, 0 to remove and 1490 not upgraded.
Need to get 38.8 MB of archives.
After this operation, 216 MB of additional disk space will be used.
Do you want to continue? [Y/n]
输入Y
安装结束:启动Docker
sudo systemctl enable docker
sudo systemctl start docker-ce
测试Docker
sudo docker run hello-world
安装成功信息
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
3 镜像加速
使用国内镜像进行加速。
打开设置文件
sudo vim /etc/docker/daemon.json
编辑命令:
i
输入内容
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
退出保存状态
esc
保存:
:wq
退出:
回车Enter
重启系统
sudo systemctl daemon-reload
重启Docker
sudo systemctl restart docker
4 Docker相关指令
4.1 查看信息
版本信息
docker --version
- 信息
Docker version 18.03.0-ce, build 0520e24
详细信息
sudo docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 18.03.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.15.0-45-generic
Operating System: Ubuntu 16.04.6 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.814GiB
Name: xhwl-Default-string
ID: U3L4:QC2V:L3QB:3YTQ:PG77:NBGR:SLTB:WWID:3HOO:G25X:RFAK:Y7WD
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
4.2 卸载
sudo apt-get purge docker-ce
4.3 删除所有信息
sudo rm -rf /var/lib/docker
4.4 后台运行docker服务
sudo docker run -d -it dockername /bin/bash
5 GPU部署
5.1 下载GPU部署文件
git clone https://github.com/*.git
cd gpu-installer
5.2 Nouveau kernel driver配置
5.2.1 检查nouveau运行状态
lsmod | grep nouveau
运行结果
nouveau 1724416 6
mxm_wmi 16384 1 nouveau
ttm 106496 1 nouveau
drm_kms_helper 172032 1 nouveau
drm 401408 9 drm_kms_helper,ttm,nouveau
i2c_algo_bit 16384 2 igb,nouveau
wmi 24576 3 intel_wmi_thunderbolt,mxm_wmi,nouveau
video 45056 1 nouveau
5.2.2 关闭Nouveau
编辑添加黑名单
sudo vim /etc/modprobe.d/blacklist.conf
添加黑名单
blacklist nouveau
安装initramfs-tools
sudo apt-get install initramfs-tools
更新initramfs
sudo update-initramfs -u
重启系统
sudo reboot
此时的系统界面分辨率降低
检查nouveau状态
lsmod | grep nouveau
此时没有输出结果,表明nouveau
已经成功关闭。
5.3 安装驱动
sudo bash nvidia-gpu-installer.sh install
5.4 安装mosquitto
sudo apt-get install mosquitto
5.5 安装firewalld
sudo apt-get install firewalld
6 小坑
nouveau运行导致GPU驱动不能安装
- Error
ERROR: The Nouveau kernel driver is currently in use by your system. This driver is
incompatible with the NVIDIA driver, and must be disabled before proceeding. Please
consult the NVIDIA driver README and your Linux distribution's documentation for
details on how to correctly disable the Nouveau kernel driver.
- Solution
参见5.2.2 关闭Nouveau。
[参考文献]
[1]https://docs.docker.com/install/linux/docker-ce/ubuntu/
[2]https://www.cnblogs.com/zhangjianbin/p/9246338.html
[3]https://www.cnblogs.com/senlinyang/p/8203191.html