Docker:它是一个开源的软件项目,在Linux操作系统上,docker提供了一个额外的软件抽象层及操作系统层虚拟化的自动管理机制。
物理机:
虚拟机:
容器化:
容器:把自己的应用程序,根据某个依赖的基础镜像,生成一个应用程序镜像
应用程序镜像,可以运行在任何部署了Docker环境的机器上。
[root@k8s-master01 ~]# docker version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.40
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:58:10 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 19.03.15
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 99e3ed8919
Built: Sat Jan 30 03:16:33 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.18.0
GitCommit: fec3683
[root@k8s-master01 ~]# docker info
Client:
Context: default
Debug Mode: false # 可以按需修改
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 6
Running: 4
Paused: 0
Stopped: 2
Images: 9
Server Version: 19.03.15
Storage Driver: overlay2 # 官方推荐的存储驱动,要求文件系统是xfs,必须支持d_type(目录条目类型,内核上的一个数据,安装系统的时候必须把ftype设置为1,不然的话很影响docker的性能),目前流行的Storage Driver有aufs(ubuntu支持)、overlay、brtfs
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file # docker日志的存储类型,json-file会存储在本地,目录在Docker Root Dir
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive # 容器编排工具,inactive未启动
Runtimes: runc
Default Runtime: runc # docker运行的核心
Init Binary: docker-init
containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.19.12-1.el7.elrepo.x86_64 # 内核版本低于3.18不能使用overlay2存储驱动,linux3.18才加入的
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.923GiB
Name: k8s-master01
ID: PYSL:2OAV:4C7N:WAI3:7G3J:IBR5:6BXI:7OEG:YNCL:6RAR:3CTF:CTDD
Docker Root Dir: /var/lib/docker # 这个目录可以修改,生产环境推荐使用ssd硬盘存储,挂载在该目录,可以提高docker的性能,条件不足的情况下,最好使用一个单独的磁盘进行挂载,不要和宿主机用同一个磁盘
Debug Mode: false
Registry: https://index.docker.io/v1/ # 官方镜像仓库,访问较慢,可以修改为自己的镜像仓库
Labels:
Experimental: false
Insecure Registries: # 如果使用的非官方镜像仓库地址不是https,需要把链接加入到此非安全列表
127.0.0.0/8
Live Restore Enabled: false # 生产环境中需要打开,重启docker进程不会重启正在运行的容器,如果容器没有设置自动重启就会被关闭,不会重启
查看d_type信息(ftype=1说明系统支持d_type)
[root@k8s-master01 ~]# xfs_info /
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
进入Docker Root Dir,进入任何一个容器目录既可查看对应容器的日志,每次docker重启的时候日志就会被清除
[root@k8s-master01 ~]# cd /var/lib/docker/containers/
[root@k8s-master01 containers]# ll
total 0
drwx-----x 4 root root 165 Jul 12 10:54 10b58a593a5f417d466fbb2eba54c6ac0e8322a3712cbc6eb46f9cae5b48e4d8
[root@k8s-master01 10b58a593a5f417d466fbb2eba54c6ac0e8322a3712cbc6eb46f9cae5b48e4d8]# ll
total 16
-rw-r----- 1 root root 4042 Jul 12 10:53 10b58a593a5f417d466fbb2eba54c6ac0e8322a3712cbc6eb46f9cae5b48e4d8-json.log
Insecure Registries目录
[root@k8s-master01 ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
],
"exec-opts": ["native.cgroupdriver=systemd"],
"max-concurrent-downloads": 10, # 并发下载的线程数
"max-concurrent-uploads": 5, # 并发上传的线程数
"log-opts": {
"max-size": "300m", # 限制日志文件最大容量,超过则分割
"max-file": "2" # 日志保存最大数量
},
"live-restore": true # 更改docker配置之后需要重启docker才能生效,这个参数可以使得重启docker不影响正在运行的容器进程
}
[root@k8s-master01 ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 6631 [OK]
ansible/centos7-ansible Ansible on Centos7 134 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 129 [OK]
jdeathe/centos-ssh OpenSSH / Supervisor / EPEL/IUS/SCL Repos - … 118 [OK]
centos/systemd systemd enabled base container. 100 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 88
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 58 [OK]
tutum/centos Simple CentOS docker image with SSH access 48
centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 45
jdeathe/centos-ssh-apache-php Apache PHP - CentOS. 31 [OK]
kinogmt/centos-ssh CentOS with SSH 29 [OK]
guyton/centos6 From official centos6 container with full up… 10 [OK]
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-install… 8 [OK]
centos/tools Docker image that has systems administration… 7 [OK]
drecom/centos-ruby centos ruby 6 [OK]
mamohr/centos-java Oracle Java 8 Docker image based on Centos 7 3 [OK]
darksheer/centos Base Centos Image -- Updated hourly 3 [OK]
miko2u/centos6 CentOS6 日本語環境 2 [OK]
amd64/centos The official build of CentOS. 2
dokken/centos-7 CentOS 7 image for kitchen-dokken 2
indigo/centos-maven Vanilla CentOS 7 with Oracle Java Developmen… 2 [OK]
mcnaughton/centos-base centos base image 1 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
starlabio/centos-native-build Our CentOS image for native builds 0 [OK]
smartentry/centos centos with smartentry 0 [OK]
OFFICIAL的值是ok代表官方容器,一般都是使用官方的
alpine可以作为基础镜像,拉取镜像的时候如果本地已经存在,则不会重复拉取
可以通过官网搜索镜像:https://hub.docker.com/
拉取镜像,如果本地已有该镜像,则不会重复拉取
[root@k8s-master01 ~]# docker pull