1、自动安装命令:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
执行结果:
[root@leyouzi ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: 93d2499759296ac1f9c510605fef85052a2c32be
+ sh -c 'yum install -y -q yum-utils'
+ sh -c 'yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo'
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
CentOS-8 - AppStream 307 kB/s | 4.3 kB 00:00
CentOS-8 - Base 590 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 221 kB/s | 1.5 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 571 kB/s | 4.7 kB 00:00
Docker CE Stable - x86_64 78 kB/s | 19 kB 00:00
Metadata cache created.
+ '[' -n '' ']'
+ sh -c 'yum install -y -q docker-ce'
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Importing GPG key 0x621E9F35:
Userid : "Docker Release (CE rpm) <docker@docker.com>"
Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
From : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Installed:
container-selinux-2:2.167.0-1.module_el8.5.0+911+f19012f9.noarch containerd.io-1.4.12-3.1.el8.x86_64 docker-ce-3:20.10.11-3.el8.x86_64 docker-ce-cli-1:20.10.11-3.el8.x86_64
docker-ce-rootless-extras-20.10.11-3.el8.x86_64 docker-scan-plugin-0.9.0-3.el8.x86_64 fuse-common-3.2.1-12.el8.x86_64 fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64
fuse3-3.2.1-12.el8.x86_64 fuse3-libs-3.2.1-12.el8.x86_64 libcgroup-0.41-19.el8.x86_64 libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64
slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64
+ version_gte 20.10
+ '[' -z '' ']'
+ return 0
+ sh -c 'yum install -y -q docker-ce-rootless-extras'
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/CentOS-epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
[root@leyouzi ~]#
2、查看docker版本:
docker -v
执行结果:
[root@leyouzi ~]# docker -v
Docker version 20.10.11, build dea9396
[root@leyouzi ~]#
3、docker启动、停止、状态命令:
sudo systemctl start docker
sudo systemctl stop docker
sudo systemctl status docker
执行结果:
[root@leyouzi ~]# sudo systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
[root@leyouzi ~]#
[root@leyouzi ~]# sudo systemctl start docker
[root@leyouzi ~]#
[root@leyouzi ~]# sudo 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 Fri 2021-11-19 15:19:03 CST; 3s ago
Docs: https://docs.docker.com
Main PID: 51085 (dockerd)
Tasks: 8
Memory: 35.2M
CGroup: /system.slice/docker.service
└─51085 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.461468202+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.464650375+08:00" level=warning msg="Your kernel does not support cgroup blkio weight"
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.464690835+08:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.464986282+08:00" level=info msg="Loading containers: start."
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.670773375+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set>
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.754755491+08:00" level=info msg="Loading containers: done."
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.778686009+08:00" level=info msg="Docker daemon" commit=847da18 graphdriver(s)=overlay2 version=20.10.11
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.778811452+08:00" level=info msg="Daemon has completed initialization"
Nov 19 15:19:03 leyouzi systemd[1]: Started Docker Application Container Engine.
Nov 19 15:19:03 leyouzi dockerd[51085]: time="2021-11-19T15:19:03.806596529+08:00" level=info msg="API listen on /var/run/docker.sock"
[root@leyouzi ~]#
4、docker Hello World!!!
docker run hello-world
执行结果:
[root@leyouzi ~]# 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/
[root@leyouzi ~]#