一、容器先容
1、容器是什么?
轻量级假造化技能
应用场景:
1、快速构建业务环境
2、便于业务迁移,避免兼容性问题
2、与传统假造化区别
创建速度快, 秒级
无假造硬件
共享物理机内核、IO速度快
3、容器的三要素
容器、镜像、堆栈
4、容器核心技能
- namespace技能 命名空间
实现资源(文件目录、用户、端口、进程)隔离
- cgroup技能
实现容器的资源限制(cpu、内存)
5、容器管理工具/软件
- docker
docker-ce、docker-ee
- podman
- containerd
二、安装docker
1、配置docker软件堆栈
- [root@martin-host ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- [root@martin-host ~]# cat /etc/yum.repos.d/docker-ce.repo
- [docker-ce]
- name=docker-ce
- baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7.9/x86_64/stable/
- enabled=1
- gpgcheck=0
复制代码 2、安装docker, 启动docker服务
- [root@martin-host ~]# yum install -y docker-ce
- [root@martin-host ~]# rpm -q docker-ce
- docker-ce-26.1.4-1.el7.x86_64
- [root@martin-host ~]# systemctl enable --now docker
- Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
- [root@martin-host ~]#
复制代码 3、配置国内docker镜像堆栈
- [root@martin-host ~]# cat /etc/docker/daemon.json
- {
- "registry-mirrors": ["https://rywdmoco.mirror.aliyuncs.com"]
- }
- [root@martin-host ~]#
- [root@martin-host ~]# systemctl restart docker
复制代码 4、主机网络厘革
- // docker0虚拟网卡,默认作为所有容器的网关使用
- [root@martin-host ~]# ip addr show docker0
- 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
- link/ether 02:42:81:00:b2:4b brd ff:ff:ff:ff:ff:ff
- inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
- valid_lft forever preferred_lft forever
- // 路由转发
- [root@martin-host ~]# cat /proc/sys/net/ipv4/ip_forward
- 1
- // docker网段的SNAT规则
- [root@martin-host ~]# iptables -t nat -nL
- Chain PREROUTING (policy ACCEPT)
- target prot opt source destination
- DOCKER all -- 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
- Chain INPUT (policy ACCEPT)
- target prot opt source destination
- Chain OUTPUT (policy ACCEPT)
- target prot opt source destination
- DOCKER all -- 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL
- Chain POSTROUTING (policy ACCEPT)
- target prot opt source destination
- MASQUERADE all -- 172.17.0.0/16 0.0.0.0/0
- Chain DOCKER (2 references)
- target prot opt source destination
- RETURN all -- 0.0.0.0/0 0.0.0.0/0
复制代码 三、镜像底子操作
1、检察镜像
- [root@martin-host ~]# docker image ls
- REPOSITORY TAG IMAGE ID CREATED SIZE
- httpd latest dabbfbe0c57b 2 years ago 144MB
- nginx 1.18 c2c45d506085 3 years ago 133MB
复制代码 2、搜索镜像
- [root@martin-host ~]# docker search 关键字
复制代码 3、下载镜像
- [root@martin-host ~]# docker pull 镜像名称:标记
复制代码 4、导入镜像
- [root@martin-host ~]# docker load -i centos7.tar
- 174f56854903: Loading layer [==================================================>] 211.7MB/211.7MB
- Loaded image: centos:7
复制代码 5、导出镜像
- [root@martin-host ~]# docker save -o tomcat.tar tomcat:latest
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |