基于Ubuntu20.04实现安装docker

1.网络安装

参考官方文档

http://www.docker.com

 

 

选择安装操作系统

 

这里选择安装系统以及版本

 

这里选择ubuntu安装docker

 

参考官方文档安装

https://docs.docker.com/engine/install/ubuntu/
1.	apt-get remove docker docker-engine docker.io containerd runc
2.	apt-get update
3.	apt-get install \ ca-certificates \ curl \
gnupg \
lsb-release
4.	curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor
-o /usr/share/keyrings/docker-archive-keyring.gpg
5.	echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker- archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >
/dev/null
6.	apt-get update
7.	apt-get install docker-ce docker-ce-cli containerd.io -y
8.	apt-cache madison docker-ce
9.	apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
10.	docker run hello-world

测试

#查看版本
root@ze-virtual-machine:~# docker version Client: Docker Engine - Community
Version:	20.10.14
API version:	1.41
Go version:	go1.16.15
Git commit:	a224086
Built:	Thu Mar 24 01:48:02 2022
OS/Arch:	linux/amd64
Context:	default
Experimental:	true


Server: Docker Engine - Community Engine:
Version:	20.10.14
API version:	1.41 (minimum version 1.12) Go version:	go1.16.15
Git commit:	87a90dc
Built:	Thu Mar 24 01:45:53 2022
OS/Arch:	linux/amd64
Experimental:	false containerd:
Version:	1.5.11
GitCommit:	3df54a852345ae127d1fa3092b95168e4a88e2f8 runc:
Version:	1.0.3
GitCommit:	v1.0.3-0-gf46b6ba docker-init:
Version:	0.19.0
GitCommit:	de40ad0

#测试
root@ze-virtual-machine:~# docker run hello-world


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/

查看service文件

root@ze-virtual-machine:~# cat /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

核心目录

软件数据目录 /var/lib/docker/
专属服务目录 /etc/docker

2.​​​​​离线安装

获取软件
mkdir /data/softs
wget -c https://download.docker.com/linux/static/stable/x86_64/docker- 20.10.14.tgz
解压软件
tar xf docker-20.10.14.tgz -C /usr/local/bin --strip-components=1
注意:
--strip-components=1 表示仅仅将该压缩文件中的内容,解压到指定的目录中

定制系统服务

root@ubuntu2004:/data/softs# mkdir /var/lib/docker /etc/docker
root@ubuntu2004:/data/softs# vim /usr/lib/systemd/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/bin/dockerd -H unix:///var/run/docker.sock --data-root=/var/lib/docker
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target

定制服务启动参数文件
# vim /etc/docker/daemon.json
{
"registry-mirrors": [], "insecure-registries": []
}

用户基本配置

创建用户组
groupadd docker
将当前用户加入到指定用户组usermod -aG docker $USER 更新用户组
newgrp docker
注意:
如果没有docker组的话,会导致如下的报错:
could not change group /var/run/docker.sock to docker: group docker not found
重载配置文件
systemctl daemon-reload
systemctl start docker 
systemctl enable docker

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhu1241jie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值