什么是docker博杖?
Docker是通過內(nèi)核虛擬化技術(namespaces及cgroups)來提供容器的資源隔離與資源限制。由于Docker通過操作系統(tǒng)層的虛擬化實現(xiàn)隔離(對操作系統(tǒng)的內(nèi)核有要求,centos6已經(jīng)沒辦法安裝最新版docker陌选,至少需要centos7的系統(tǒng)替蔬,如果需要最新docker特性岩遗,需要使用unbantu覆履,因為redhalt內(nèi)核比unbantu內(nèi)核版本低)囚巴,所以Docker容器在運行時德挣,不需要類似虛擬機(VM)額外的操作系統(tǒng)開銷,從而比kvm虛擬機更輕量圈匆。 docker是一種軟件的打包技術漠另。
docker理念
docker的主要目標是"Build,Ship and Run any App,Angwhere",構建,運輸跃赚,處處運行 構建:制作docker鏡像笆搓,打包容器的所有系統(tǒng)目錄文件 運輸:下載docker鏡像 運行:基于docker鏡像提供的rootfs,啟動容器 總結(jié):只要能運行docker容器纬傲,那么docker鏡像中已經(jīng)安裝好的軟件也可以運行满败,所以說docker是一種軟件的打包技術,一次構建叹括,出處運行算墨。
docker的優(yōu)點
1.解決了操作系統(tǒng)和軟件運行環(huán)境的依賴
2.對于開發(fā)人員來說,再也不用擔心不會部署開發(fā)環(huán)境
3.開發(fā)環(huán)境汁雷,測試環(huán)境和生產(chǎn)環(huán)境高度一致净嘀。
4.讓用戶體驗產(chǎn)品新特性的又一種思路。
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最重要的三大組件: 鏡像挖藏,容器,倉庫