Dcoker是基于容器技术的轻量级虛拟化解决方案,docker是由容器引擎,把linux的cgroup、namespaces等容器底层技术进行完美的封装、并抽象为用户提供创建和管理容器的便捷界面(命令行Cli、api等) C/s
Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。
Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。
容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。
Docker 从 17.03 版本之后分为 CE(Community Edition: 社区版) 和 EE(Enterprise Edition: 企业版)。
6个名称空间介绍如下:
①、mount:文件系统,挂载点------->一个文件系统内,不能重复挂载一个指定目录
②、user:操作进程的用户和用户组
③、pid:进程编号
④、uts:主机名和主机域
⑤、ipc:信号量、消息队列,共享内存
⑥、net:网络设备、网络协议栈、端口等
特性 | Docker | 虚拟机 |
---|---|---|
启动速度 | 秒级 | 分钟级 |
计算能力损耗 | 接近无 | 损耗50%左右 |
磁盘占用 | MB级 | GB级 |
数量 上千个 | (进程) | 几十个(操作系统) |
隔离性 | 进程级别 | 系统级别 |
封装程度 | 只打包项目代码和依赖关系,共享宿主机内核 | 完整的操作系统,与宿主机隔离 |
操作系统 | 主要支持Linux | 几乎所有 |
[root@localhost opt]# systemctl stop firewalld.service
[root@localhost opt]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost opt]# setenforce 0
[root@localhost opt]# vim /etc/selinux/config
SELINUX=disabled
[root@localhost opt]# vim /etc/resolv.con
nameserver 114.114.114.114
[root@localhost opt]# yum install -y yum-utils device-mapper-persistent-data lvm2
device:存储驱动 lvm2:控制工具
[root@localhost opt]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件: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
[root@localhost yum.repos.d]# yum -y install docker-ce
[root@localhost yum.repos.d]# systemctl start docker
[root@localhost yum.repos.d]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.servic
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://8*****.mirror.aliyuncs.com"]
}
EOF
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker
[root@localhost docker]# cat daemon.json
{
"registry-mirrors": ["https://8eueg49g.mirror.aliyuncs.com"]
}
[root@localhost docker]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
[root@localhost docker]# sysctl -p
net.ipv4.ip_forward = 1
[root@localhost docker]# systemctl restart network
[root@localhost docker]# systemctl restart docker
三种方法:
[root@localhost docker]# docker -v
Docker version 20.10.8, build 3967b7d
[root@docker ~]# docker version
Client: Docker Engine - Community
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:55:49 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:54:13 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
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: Build with BuildKit (Docker Inc., v0.6.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 2
Server Version: 20.10.8
Storage Driver: overlay2
Backing Filesystem: xfs
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: e25210fe30a0a703442421b0f60afac609f950a3
runc version: v1.0.1-0-g4144b63
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-957.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.683GiB
Name: docker
ID: 4KTG:EZRQ:4XKL:FLOB:BPPH:J3SS:LLT7:E2ZS:YUVE:L73B:AIFH:6ABL
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://rpw1odqr.mirror.aliyuncs.com/
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
①:配置文件vim /etc/docker/daemon.json内添加"bip": “IP地址/24”
②:命令行配置:
[root@localhost docker]# vim /etc/docker/daemon.json
{
"graph": "/data/docker", ##数据目录
"storage-driver": "overlay2", ##存储引擎;版本迭代:LXC——>overlay——>overlay2(overlayfs:文件系统,解决docker镜像分层)
"insecure-registries": [" registry.access.redhat.com", "quary.io"] ##私有仓库位置
"registry-mirrors": ["https://***"] ##镜像加速
"bip": "172.17.0.1/24", ##docker网络;控制网段的位置;需要创建新的网桥,系统默认的docker0是不变的
"exec-opts": ["native.cgroupdriver-systemd"], ##启动时候的额外参数(驱动)
"live-restore":true ##当docker容器引擎挂掉的时候,使用docker跑起来的容器还能运行(分离)
}