安装依赖

1
2
sudo apt-get install     ca-certificates     curl     gnupg     lsb-release -y
sudo mkdir -p /etc/apt/keyrings

添加官方GPG密钥:

1
sudo curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

添加Docker的稳定版本仓库:

1
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

创建用户

1
2
sudo useradd docker
sudo usermod -aG docker $USER

安装Docker

腾讯云使用

1
2
sudo apt-get update
sudo apt-get install docker.io -y

挂载磁盘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
root@ubuntu:/var/lib# fdisk -l

Disk /dev/vda: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 884D39AE-2030-4231-B486-520515A9ADD7

Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 104857566 104853471 50G Linux filesystem


Disk /dev/vdb: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root@ubuntu:/var/lib# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x1c765732.

Command (m for help): `p`
Disk /dev/vdb: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1c765732

Command (m for help): `n`
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): `p`
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-419430399, default 419430399):

Created a new partition 1 of type 'Linux' and of size 200 GiB.

Command (m for help): `w`
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@ubuntu:/var/lib# mkfs.ext4 /dev/vdb1
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 52428544 4k blocks and 13107200 inodes
Filesystem UUID: a75b2a51-daa1-4d05-a6ee-0871fb0cf059
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

root@ubuntu:/var/lib# mkdir /data
root@ubuntu:/# mount /dev/vdb1 /data
root@ubuntu:/# df -h
Filesystem Size Used Avail Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 3.1G 808K 3.1G 1% /run
/dev/vda2 50G 19G 29G 39% /
tmpfs 16G 24K 16G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 16G 0 16G 0% /sys/fs/cgroup
tmpfs 3.1G 0 3.1G 0% /run/user/1000
/dev/vdb1 196G 28K 186G 1% /data

修改存储路径

1
2
3
4
5
6
7
8
9
#Docker的镜像需在大量的存储空间,默认的存储路径在 /var/lib/docker, 可以按实际需求修改存储路径。
#停止docker
systemctl stop docker
#移动目录到新路径
sudo mv /var/lib/docker /data/docker
#做个软链接
ln -s /data/docker /var/lib/docker
#启动docker
systemctl start docker

安装GPU驱动

1
2
3
4
5
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
systemctl restart docker

验证驱动

1
sudo nvidia-smi