前期准备
centos7的服务器或者虚拟机
【CentOS下载地址】,安装虚拟机的教程自行百度下。
docker安装
1、安装yum-utils,sudo yum install -y yum-utils
[root@*** ~]# sudo yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Determining fastest mirrors
* base: 100.125.0.40
* extras: 100.125.0.40
* updates: 100.125.0.40
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-42.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-50.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Updating:
yum-utils noarch 1.1.31-50.el7 base 121 k
Transaction Summary
==============================================================================================================================================================================================================================================================================
Upgrade 1 Package
Total download size: 121 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
yum-utils-1.1.31-50.el7.noarch.rpm | 121 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : yum-utils-1.1.31-50.el7.noarch 1/2
Cleanup : yum-utils-1.1.31-42.el7.noarch 2/2
Verifying : yum-utils-1.1.31-50.el7.noarch 1/2
Verifying : yum-utils-1.1.31-42.el7.noarch 2/2
Updated:
yum-utils.noarch 0:1.1.31-50.el7
Complete!
2、指定仓库源,sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@*** ~]# sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
3、安装docker-ce,sudo yum install -y docker-ce
[root@*** ~]# sudo yum install -y docker-ce
Loaded plugins: fastestmirror, langpacks
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/x86_64/primary_db
.
.
.
Dependency Updated:
libselinux.i686 0:2.5-14.1.el7 libselinux.x86_64 0:2.5-14.1.el7 libselinux-python.x86_64 0:2.5-14.1.el7 libselinux-utils.x86_64 0:2.5-14.1.el7 libsemanage.x86_64 0:2.5-14.el7 libsemanage-python.x86_64 0:2.5-14.el7
libsepol.i686 0:2.5-10.el7 libsepol.x86_64 0:2.5-10.el7 policycoreutils.x86_64 0:2.5-29.el7_6.1 policycoreutils-python.x86_64 0:2.5-29.el7_6.1 selinux-policy.noarch 0:3.13.1-229.el7_6.12 selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.12
setools-libs.x86_64 0:3.3.8-4.el7
Complete!
4、启动docker,sudo service docker start
[root@*** ~]# sudo service docker start
Redirecting to /bin/systemctl start docker.service
emmmm,使用systemctl命令,systemctl start docker
[root@*** ~]# systemctl start docker
5、查看docker状态,systemctl status docker
[root@*** ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2019-09-10 11:29:42 CST; 4min 20s ago
Docs: https://docs.docker.com
Main PID: 21423 (dockerd)
Memory: 47.0M
CGroup: /system.slice/docker.service
└─21423 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
.
.
.
6、设置开机启动,systemctl enable docker
[root@*** ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
7、创建daemon.json,vi /etc/docker/daemon.json
{
"registry-mirrors":["https://********.mirror.aliyuncs.com"]
}
8、 重启docker,systemctl restart docker
[root@*** ~]# systemctl restart docker
9、查看docker信息,docker info
[root@*** ~]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.2
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
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: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.639GiB
Name: ecs-8c5d-0619058.novalocal
ID: OAWX:4BH6:KMYM:DTVV:BYE5:5WQU:HYHT:YHX3:DQRI:OTSN:OU3M:A2HN
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://******.mirror.aliyuncs.com/
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
10、测试,docker run hello-world
[root@*** ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:451ce787d12369c5df2a32c85e5a03d52cbcef6eb3586dd03075f3034f10adcd
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/
11、关闭docker,systemctl stop docker
[root@*** ~]# systemctl stop docker
[root@*** ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2019-09-10 11:56:52 CST; 15s ago
Docs: https://docs.docker.com
Process: 21775 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=0/SUCCESS)
Main PID: 21775 (code=exited, status=0/SUCCESS)
.
.
.
12、卸载
1)、查询已安装关于docker的文件, yum list installed | grep docker
[root@*** ~]# yum list installed | grep docker
containerd.io.x86_64 1.2.6-3.3.el7 @docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 @docker-ce-stable
docker-ce-cli.x86_64 1:19.03.2-3.el7 @docker-ce-stable
2)、删除已安装的文件,yum -y remove containerd.io.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64
[root@*** ~]# yum -y remove containerd.io.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.6-3.3.el7 will be erased
---> Package docker-ce.x86_64 3:19.03.2-3.el7 will be erased
---> Package docker-ce-cli.x86_64 1:19.03.2-3.el7 will be erased
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00:00
docker-ce-stable/x86_64 | 3.5 kB 00:00:00
docker-ce-stable/x86_64/primary_db | 36 kB 00:00:00
epel-apache-maven/7/x86_64 | 3.3 kB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
Dependencies Resolved
======================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================
Removing:
containerd.io x86_64 1.2.6-3.3.el7 @docker-ce-stable 96 M
docker-ce x86_64 3:19.03.2-3.el7 @docker-ce-stable 104 M
docker-ce-cli x86_64 1:19.03.2-3.el7 @docker-ce-stable 169 M
Transaction Summary
======================================================================================================================================================
Remove 3 Packages
Installed size: 368 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 3:docker-ce-19.03.2-3.el7.x86_64 1/3
Erasing : containerd.io-1.2.6-3.3.el7.x86_64 2/3
Erasing : 1:docker-ce-cli-19.03.2-3.el7.x86_64 3/3
Verifying : 3:docker-ce-19.03.2-3.el7.x86_64 1/3
Verifying : containerd.io-1.2.6-3.3.el7.x86_64 2/3
Verifying : 1:docker-ce-cli-19.03.2-3.el7.x86_64 3/3
Removed:
containerd.io.x86_64 0:1.2.6-3.3.el7 docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-cli.x86_64 1:19.03.2-3.el7
Complete!
3)、删除docker,路径为docker info 中的Docker Root Dir
[root@*** ~]# rm -rf /var/lib/docker
如果有写的不对的地方,请大家多多批评指正,非常感谢!