Docker安装(RPM包方式)
一、安装环境准备
1、操作系统要求
#1、查看内核版本
[root@nod var]# uname -r
3.10.0-957.el7.x86_64
#2、查看操作系统版本
[root@nod var]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
#3、关闭防火墙
[root@nod var]# systemctl stop firewalld
[root@nod var]# systemctl disable firewalld
[root@nod var]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
#4、关闭SElinux
[root@nod var]vim /etc/selinux/config
[root@nod var]# getenforce
Disabled
#5、查看iptables是否被启动
[root@nod selinux]# systemctl status iptables
#若没有安装进行iptables进行安装
[root@nod selinux]# yum -y install iptables-services
#启动iptables
[root@nod selinux]# systemctl start iptables
#设置为开机自启
[root@nod selinux]# sysatemctl enable iptables
#查看iptables的状态
[root@nod selinux]# systemctl status iptables
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Thu 2021-12-02 10:18:29 CST; 31s ago
Main PID: 3796 (code=exited, status=0/SUCCESS)
Dec 02 10:18:29 nod systemd[1]: Starting IPv4 firewall with iptables...
Dec 02 10:18:29 nod iptables.init[3796]: iptables: Applying firewall rules: [ OK ]
Dec 02 10:18:29 nod systemd[1]: Started IPv4 firewall with iptables.
#清空防火墙
[root@nod selinux]# iptables -F
#保存防火墙
[root@nod selinux]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
#查看防火墙状态
[root@nod selinux]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
#建议更新软件包
[root@nod selinux]# yum update
#重启并使用最新的内核启动
[root@nod selinux]# shutdown -h now
#升级之后的内核版本
[root@nod ~]# uname -r
3.10.0-1160.49.1.el7.x86_64
2、判断是否存在老版本Docker进行卸载
root@nod system]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
Loaded plugins: fastestmirror, langpacks
No Match for argument: docker-client-latest
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos will be erased
---> Package docker-client.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos will be erased
---> Package docker-common.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos will be erased
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00:00
extras/7/x86_64 | 2.9 kB 00:00:00
kubernetes/signature | 844 B 00:00:00
kubernetes/signature | 1.4 kB 00:00:00 !!!
mysql-connectors-community/x86_64 | 2.6 kB 00:00:00
mysql-tools-community/x86_64 | 2.6 kB 00:00:00
mysql57-community/x86_64 | 2.6 kB 00:00:00
nginx/x86_64 | 2.9 kB 00:00:00
updates/7/x86_64 | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 13 MB 00:00:02
Dependencies Resolved
==================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================
Removing:
docker x86_64 2:1.13.1-96.gitb2f74b2.el7.centos @extras 65 M
docker-client x86_64 2:1.13.1-96.gitb2f74b2.el7.centos @extras 13 M
docker-common x86_64 2:1.13.1-96.gitb2f74b2.el7.centos @extras 4.4 k
Transaction Summary
==================================================================================================================================================
Remove 3 Packages
Installed size: 77 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 2:docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64 1/3
warning: /etc/sysconfig/docker-storage saved as /etc/sysconfig/docker-storage.rpmsave
Erasing : 2:docker-client-1.13.1-96.gitb2f74b2.el7.centos.x86_64 2/3
Erasing : 2:docker-common-1.13.1-96.gitb2f74b2.el7.centos.x86_64 3/3
warning: /etc/sysconfig/docker saved as /etc/sysconfig/docker.rpmsave
Verifying : 2:docker-client-1.13.1-96.gitb2f74b2.el7.centos.x86_64 1/3
Verifying : 2:docker-common-1.13.1-96.gitb2f74b2.el7.centos.x86_64 2/3
Verifying : 2:docker-1.13.1-96.gitb2f74b2.el7.centos.x86_64 3/3
Removed:
docker.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos docker-client.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos
docker-common.x86_64 2:1.13.1-96.gitb2f74b2.el7.centos
Complete!
[root@nod var]# rm -rf /var/lib/docker/
3、安装Docker
3.1、下载Docker安装包
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
下载rpm包:
docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm
docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
3.2、上传Docker安装包
#1、把docker安装包上传到/root/docker目录下
[root@nod ~]# mkdir docker
[root@nod ~]# cd docker/
[root@nod docker]# ll
total 19096
-rw-r--r-- 1 root root 19521288 Dec 2 18:55 docker-ce-17.03.0.ce-1.el7.centos.x86_64.rpm
-rw-r--r-- 1 root root 29108 Dec 2 18:55 docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
#2、到/root/docker目录下执行安装
[root@nod docker]# yum -y install *
#5、启动docker、设置开机自启
[root@nod docker]# systemctl start docker
[root@nod docker]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@nod docker]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2021-12-02 19:03:22 CST; 3min 31s ago
Docs: https://docs.docker.com
Main PID: 15149 (dockerd)
Tasks: 16
Memory: 18.6M
CGroup: /system.slice/docker.service
├─15149 /usr/bin/dockerd
└─15152 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/li...
Dec 02 19:03:21 nod dockerd[15149]: time="2021-12-02T19:03:21.669802339+08:00" level=info msg="libcontainerd: new containerd process, pid: 15152"
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.708279181+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.708753767+08:00" level=info msg="Loading containers: start."
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.750365984+08:00" level=info msg="Firewalld running: false"
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.802537319+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0...IP address"
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.917607672+08:00" level=info msg="Loading containers: done."
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.924340194+08:00" level=info msg="Daemon has completed initialization"
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.924378985+08:00" level=info msg="Docker daemon" commit=3a232c8 graphdriver=overlay version=17.03.0-ce
Dec 02 19:03:22 nod dockerd[15149]: time="2021-12-02T19:03:22.937997324+08:00" level=info msg="API listen on /var/run/docker.sock"
Dec 02 19:03:22 nod systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@nod docker]# docker version
Client:
Version: 17.03.0-ce
API version: 1.26
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:10:07 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.0-ce
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:10:07 2017
OS/Arch: linux/amd64
Experimental: false
[root@nod docker]# docker version
Client:
Version: 17.03.0-ce
API version: 1.26
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:10:07 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.0-ce
API version: 1.26 (minimum version 1.12)
Go version: go1.7.5
Git commit: 3a232c8
Built: Tue Feb 28 08:10:07 2017
OS/Arch: linux/amd64
Experimental: false
#运行hello的镜像
[root@nod docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/
二进制包的安装方式(生产下不建议使用)参考:https://blog.csdn.net/ruth13156402807/article/details/116457261
官方文档:https://docs.docker.com/engine/install/binaries/
4、Docker卸载
#1、卸载依赖
yum remove docker-ce docker-ce-li containerd.io
#2、删除资源
rm -rf /var/lib/docker
5、Docker国内镜像
#1、创建或修改/etc/docker/daemon.json文件
[root@nod docker]# vim /etc/docker/daemon.json
{
"registry-mirrors":["https://4jxxx3m1.mirror.aliyuncs.com"]
}
#2、加载资源,重启docker
[root@nod docker]# systemctl daemon-reload
[root@nod docker]# systemctl restart docker
#3、通过docker info查看当前镜像库
[root@nod ~]# docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 2
Server Version: 17.03.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 977c511eda0925a723debdc94d09459af49d082a
runc version: a01dafd48bc1c7cc12bdb01206f9fea7dd6feb70
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.49.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.84 GiB
Name: nod
ID: C2ZM:GVN6:EQJQ:ZFKA:ORO4:5HOW:A25A:6TYF:4H3R:UFB6:NW7Z:UWZV
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://4xxxx3m1.mirror.aliyuncs.com
Live Restore Enabled: false