文檔:https://docs.docker.com/install/linux/docker-ce/centos/
中文文檔:https://docs.docker-cn.com/engine/installation/linux/docker-ce/centos/#prerequisites
1、CentOS6.5安裝Docker
Docker使用EPEL發布,RHEL系的OS首先要確保已經持有EPEL倉庫,否則先檢查OS的版本,然后安裝相應的EPEL包。
yum install -y epel-release
yum install -y docker-io
安裝后的配置文件:/etc/sysconfig/docker
啟動Docker后台服務:service docker start
docker version驗證
2、CentOS7安裝Docker
yum安裝gcc相關:
yum -y install gcc
yum -y install gcc-c++
卸載舊版本:
yum -y remove docker docker-common docker-selinux docker-engine
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
安裝需要的軟件包:
yum install -y yum-utils device-mapper-persistent-data lvm2
設置stable鏡像倉庫:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum軟件包索引:
yum makecache fast
安裝DOCKER CE:
yum -y install docker-ce
啟動Docker:
systemctl start docker
測試是否安裝成功:
docker version
配置鏡像加速
mkdir -p /etc/docker
vim /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
daemon.json:
#網易雲
{"registry-mirrors": ["http://hub-mirror.c.163.com"] }
#阿里雲
{
"registry-mirrors": ["https://{阿里雲上查看}.mirror.aliyuncs.com"]
}
卸載:
systemctl stop docker
yum -y remove docker-ce
rm -rf /var/lib/docker
3、快速開始
Docker運行Hello-World鏡像:
docker run hello-world
輸出信息
#在本地找不到Hello-world鏡像
Unable to find image 'hello-world:latest' locally
#從遠程倉庫中拉
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
Status: Downloaded newer image for hello-world:latest
#代表Docker環境安裝、運行、配置完成
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
4、Docker Run
Docker Run執行流程:
- Docker查詢鏡像
- 本地找到則使用本地鏡像
- 本地未找到去遠程倉庫查找鏡像
- 找到鏡像后以鏡像生成容器進行運行
5、Docker運行原理
Docker是一個Client-Server結構的系統,Docker守護進程運行在主機上, 然后通過Socket連接從客戶端訪問,守護進程從客戶端接受命令並管理運行在主機上的容器。 容器,是一個運行時環境,就是Docker Log 上的集裝箱。
為什么Docker比較比VM快?
-
docker有着比虛擬機更少的抽象層。由亍docker不需要Hypervisor實現硬件資源虛擬化,運行在docker容器上的程序直接使用的都是實際物理機的硬件資源。因此在CPU、內存利用率上docker將會在效率上有明顯優勢。
-
docker利用的是宿主機的內核,而不需要Guest OS。因此,當新建一個容器時,docker不需要和虛擬機一樣重新加載一個操作系統內核。仍而避免引尋、加載操作系統內核返個比較費時費資源的過程,當新建一個虛擬機時,虛擬機軟件需要加載Guest OS,返個新建過程是分鍾級別的。而docker由於直接利用宿主機的操作系統,則省略了返個過程,因此新建一個docker容器只需要幾秒鍾。