环境:Centos7.9
1、docker包的下载,下载到本地
官方地址:Index of linux/static/stable/x86_64/
1.1 或者将docker包下载到虚拟机
可以使用wget命令或者curl命令
wget https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz
curl -O https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz
下载完成之后就会有你下载指定docker版本的包
1.2 解压docker包,会得到docker目录
tar -xvf docker-24.0.7.tgz
1.3 将解压得到的docker目录里面的所有文件复制到/usr/bin/下面
cp docker/* /usr/bin/
说明:不要将docker目录复制过去,是将docker目录里面的文件复制过去,如果将目录复制过去会造成路径错误,会使docker启动不起来。
1.4 将docker交给systemctl进行管理
首先编辑一个docker.service文件
vi /usr/lib/systemd/system/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
# 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 --selinux-enabled=false
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
1.5 启动docker
给docker.service文件添加执行权限:
chmod +x /usr/lib/systemd/system/docker.service
重新加载配置文件:
systemctl daemon-reload
启动docker并将docker加入开机自启动:
systemctl start docker
systemctl enable docker
1.6 查看docker服务的状态
systemctl status docker
docker info
docker --version
docker info 可以查看docker的信息,包括版本
[root@ansible3 docker]# docker info
Client:
Version: 24.0.7
Context: default
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 24.0.7
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 091922f03c2762540fd057fba91260237ff86acb
runc version: v1.1.9-0-gccaecfc
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 3.10.0-1160.102.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 972.1MiB
Name: ansible3
ID: 3811aae0-d0e9-4196-9604-d4cef402e1e3
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine