docker官网:www.docker.com
官网文档:docs.docker.com
随机密码生成:pwmake 数字
安装
安装前准备
- 查看系统和内核版本
[root@docker ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@docker ~]#
[root@docker ~]# uname -a
Linux docker 3.10.0-1160.92.1.el7.x86_64 #1 SMP Tue Jun 20 11:48:01 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
- 关闭防火墙和SELinux
[root@docker ~]# systemctl stop firewalld
[root@docker ~]# systemctl disable firewalld
[root@docker ~]# setenforce 0
setenforce: SELinux is disabled
[root@docker ~]#
[root@docker ~]# getenforce
Disabled
- 卸载旧版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
使用 yum 安装
- 配置仓库
yum install -y yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 使用阿里云软件源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 安装最新版本
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- 指定安装版本,本课程使用版本:20.10.24
# 查看所有版本
yum list docker-ce --showduplicates | sort -r
# 安装
yum -y install docker-ce-20.10.24-3.el7.x86_64 docker-ce-cli-20.10.24-3.el7.x86_64 containerd.io docker-buildx-plugin-0.10.5-1.el7.x86_64.rpm docker-compose-plugin
RPM包安装
访问 Index of linux/centos/ 选择CentOS版本,进入 x86_64/stable/Packages/ 目录,下载 rpm 包。
- 安装
yum install *.rpm
二进制安装
下载二进制文件
启动 Docker
./docker
测试 Docker 是否正确安装
[root@docker ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:4f53e2564790c8e7856ec08e384732aa38dc43c52f02952483e3f003afbf23db
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
版本信息
Docker 是传统的CS 架构分为Docker Client 和Docker Server
[root@docker ~]# docker version
# 客户端
Client: Docker Engine - Community
Version: 20.10.24
API version: 1.41
Go version: go1.19.7
Git commit: 297e128
Built: Tue Apr 4 18:22:57 2023
OS/Arch: linux/amd64
Context: default
Experimental: true
# 服务端
Server: Docker Engine - Community
Engine:
Version: 20.10.24
API version: 1.41 (minimum version 1.12)
Go version: go1.19.7
Git commit: 5d6db84
Built: Tue Apr 4 18:21:02 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.24
GitCommit: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc:
Version: 1.1.9
GitCommit: v1.1.9-0-gccaecfc
docker-init:
Version: 0.19.0
GitCommit: de40ad0
状态信息查看
[root@docker ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.10.4-docker)
compose: Docker Compose (Docker Inc., v2.21.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.24
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
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 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc version: v1.1.9-0-gccaecfc
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1160.92.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 15GiB
Name: docker
ID: 7MRK:ZL7D:ZQBL:CYQW:NFYH:S6NI:BGGH:K6X4:5QZX:2XRS:AIGX:CTN5
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
Live Restore Enabled: false
配置镜像加速器
Docker 配置文件 /etc/docker/daemon.json 中写入如下内容(如果文件不存在先创建):
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://ung2thfc.mirror.aliyuncs.com",
"https://mirror.ccs.tencentyun.com"
]
}
重启服务
systemctl daemon-reload
systemctl restart docker
docker run -it ubuntu sh
#下载运行一个Ubuntu操作系统
docker run -d -p80:80 nginx:1.22.1
#下载运行一个Nginx并启动
附录:
Yum 安装:
Install Docker Engine on CentOS | Docker Docs
二进制安装: