Docker 安装(方法4):使用二进制文件压缩包安装

docker 有很多种安装方式:yum 源、rpm 包、便携脚本。这里介绍另一种方式,使用二进制压缩包安装。

Here we go!!!

(1)准备 Docker CE 二进制包

下载地址:https://download.docker.com/linux/static/stable/x86_64/

这里我们选择最新的:
docker-20.10.21.tgz 2022-10-25 20:57:32 62.9 MiB
下载命令:

wget -c https://download.docker.com/linux/static/stable/x86_64/docker-20.10.21.tgz

(2)解压

root用户操作:

tar -zxvf docker-20.10.21.tgz 

改变权限:

chown root:root docker/* 

解压后的文件如下:

[root@Node01 ~]# ll docker/*
-rwxr-xr-x. 1 root root 38995448 Oct 26 02:03 docker/containerd
-rwxr-xr-x. 1 root root  7446528 Oct 26 02:03 docker/containerd-shim
-rwxr-xr-x. 1 root root  9646080 Oct 26 02:03 docker/containerd-shim-runc-v2
-rwxr-xr-x. 1 root root 20750336 Oct 26 02:03 docker/ctr
-rwxr-xr-x. 1 root root 48047088 Oct 26 02:03 docker/docker
-rwxr-xr-x. 1 root root 57789848 Oct 26 02:03 docker/dockerd
-rwxr-xr-x. 1 root root   765808 Oct 26 02:03 docker/docker-init
-rwxr-xr-x. 1 root root  2555160 Oct 26 02:03 docker/docker-proxy
-rwxr-xr-x. 1 root root 13847864 Oct 26 02:03 docker/runc

(3)复制二进制文件

将解压后的二进制文件复制到目录“/usr/bin”下:

cp -p docker/* /usr/bin/ 

说明:参数-p保持原来的属性。

(4)创建用户组

执行以下命令创建用户组:

groupadd docker 

(5)检查命令是否生效

执行以下命令查看版本:

docker version 

参考结果:
Client:
Version: 20.10.21
API version: 1.41
Go version: go1.18.7
Git commit: baeda1f
Built: Tue Oct 25 17:56:30 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

(6)配置相关服务文件

参考文件:docker.socket、 containerd.service、 docker.service

6.1 docker.socket

tee /usr/lib/systemd/system/docker.socket <<EOF
[Unit]
Description=Docker Socket for the API

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
EOF

6.2 containerd.service

tee /usr/lib/systemd/system/containerd.service <<EOF
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5

# Having non-zero Limit*s causes performance problems due to accounting overhead

# in the kernel. We recommend using cgroups to do container-local accounting.

LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity

# Comment TasksMax if your systemd version does not supports it.

# Only systemd 226 and above support this version.

TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target
EOF

6.3 docker.service

tee /usr/lib/systemd/system/docker.service <<EOF
[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
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

StartLimitBurst=3

StartLimitInterval=60s

LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

TasksMax=infinity

Delegate=yes

KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target
EOF

(7)启用 dockerd 服务:

启动 dockerd 服务进程。

systemctl enable docker.service 

查看状态:

 systemctl is-enabled docker.socket docker.service containerd.service 

分别是:disabled、enabled、disabled

启动:

systemctl start docker.service 

查看状态:

systemctl status docker.socket docker.service containerd.service 

一条命令搞定启用和运行:

systemctl enable --now docker.service 

(8)检验

查看进程:

ps aux | grep docker 

结果参考:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 7497 0.3 0.9 1271336 36944 ? Ssl 08:05 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root 7636 0.0 0.0 112812 984 pts/0 R+ 08:07 0:00 grep --color=auto docker

通过运行镜像“hello-world”来验证 Docker Engine 是否正确安装。

sudo docker run hello-world 

这个命令下载一个测试镜像,并在容器中运行它。当容器运行时,它打印出一条消息并退出。

运行结果:

Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:faa03e786c97f07ef34423fccceeec2398ec8a5759259f94d99078f264e9d7af
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/

There you go!!!

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值