什么是docker?
Docker是通过内核虚拟化技术(namespaces及cgroups)来提供容器的资源隔离与资源限制。由于Docker通过操作系统层的虚拟化实现隔离(对操作系统的内核有要求,centos6已经没办法安装最新版docker,至少需要centos7的系统,如果需要最新docker特性,需要使用unbantu,因为redhalt内核比unbantu内核版本低),所以Docker容器在运行时,不需要类似虚拟机(VM)额外的操作系统开销,从而比kvm虚拟机更轻量。 docker是一种软件的打包技术。
docker理念
docker的主要目标是"Build,Ship and Run any App,Angwhere",构建,运输,处处运行 构建:制作docker镜像,打包容器的所有系统目录文件 运输:下载docker镜像 运行:基于docker镜像提供的rootfs,启动容器 总结:只要能运行docker容器,那么docker镜像中已经安装好的软件也可以运行,所以说docker是一种软件的打包技术,一次构建,出处运行。
docker的优点
1.解决了操作系统和软件运行环境的依赖
2.对于开发人员来说,再也不用担心不会部署开发环境
3.开发环境,测试环境和生产环境高度一致。
4.让用户体验产品新特性的又一种思路。
docker的安装
1.安装一台CentOS7(博主采用CentOS7.4)
[root@docker01 /]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
2.修改主机名为docker01
hostnamectl set-hostname docker01
3.配置yum源
#删除本地源
rm -fr /etc/yum.repos.d/local.repo
#下载阿里云源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#下载docker源
curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
#将源文件中的地址替换为清华源
sed -i 's#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#g' /etc/yum.repos.d/docker-ce.repo
4.安装docker
yum install docker-ce -y
5.启动docker,并置为开机启动
[root@docker01 /]# systemctl start docker.service
[root@docker01 /]# systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@docker01 /]# systemctl status docker.service
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2019-07-22 10:34:27 CST; 21s ago
Docs: https://docs.docker.com
Main PID: 2602 (dockerd)
CGroup: /system.slice/docker.service
└─2602 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.023394018+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc4200452e0, REA...module=grpc
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.029328234+08:00" level=info msg="pickfirstBalancer: HandleSubConnStateChange: 0xc4200450b0, REA...module=grpc
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.043464741+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.044024276+08:00" level=info msg="Loading containers: start."
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.273802596+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17...IP address"
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.334002476+08:00" level=info msg="Loading containers: done."
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.355108588+08:00" level=info msg="Docker daemon" commit=0dd43dd graphdriver(s)=overlay2 version=18.09.8
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.355245821+08:00" level=info msg="Daemon has completed initialization"
Jul 22 10:34:27 docker01 dockerd[2602]: time="2019-07-22T10:34:27.399274108+08:00" level=info msg="API listen on /var/run/docker.sock"
Jul 22 10:34:27 docker01 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
docker架构
启动docker: systemctl start docker
开机自启:systemctl enable docker
docker是一个cs架构: 通过docker version来查看
[root@docker01 /]# docker version
Client:
Version: 18.09.8
API version: 1.39
Go version: go1.10.8
Git commit: 0dd43dd87f
Built: Wed Jul 17 17:40:31 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.8
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 0dd43dd
Built: Wed Jul 17 17:10:42 2019
OS/Arch: linux/amd64
Experimental: false
docker最重要的三大组件: 镜像,容器,仓库
网友评论