Docker的基本組成
- 鏡像(images):鏡像就是一個模闆,通過這個模闆建立多個容器服務。
- 容器(containers):利用容器的技術,獨立運作一個或者多個應用,是通過鏡像建立的(了解為一個獨立的linux系統)
- 倉庫(repository):存儲鏡像的一個地方。(包括私有的倉庫和公有的倉庫)
安裝Docker
-linux 環境檢視
#系統核心是3.10以上的
[[email protected] ~]# uname -r
3.10.0-1062.el7.x86_64
-安裝docker(聯網線上安裝)
-
檢視幫助文檔
1、位址:https://docs.docker.com/get-started/overview/
2、解除安裝舊版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
3、需要的安裝包
$ sudo yum install -y yum-utils
4、設定鏡像的倉庫
(注:官網上的鏡像位址是國外的,下載下傳非常慢,我們用阿裡雲的鏡像位址)
$ sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5、安裝docker
(注:docker-ce 社群版本 docker-ee企業版本,我們一般社群版本)
##(最新版本)
$ sudo yum install docker-ce docker-ce-cli containerd.io
##(指定的版本)
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
6、檢視docker 是否安裝成功
docker version
7、啟動docker
$ sudo systemctl start docker
8、運作一個鏡像
$ sudo docker run hello-world
9、檢視hello-world 這個鏡像是否存在
docker images
10、解除安裝docker
--解除安裝軟體
$ sudo yum remove docker-ce docker-ce-cli containerd.io
--删除目錄
$ sudo rm -rf /var/lib/docker
配置鏡像加速器
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://1vxmuxs5.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Docker安裝(離線安裝)
- 下載下傳docker離線版本
https://download.docker.com/linux/static/stable/x86_64/
選擇ce版本
- 準備docker.service 系統配置檔案,檔案内容為以下内容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
- 上傳離線檔案包docker-18.06.1-ce.tgz
-
解壓
-
tar -xvf docker-18.06.1-ce.tgz
-
将解壓出來的docker檔案内容移動到 /usr/bin/ 目錄下
-
cp docker/* /usr/bin/
- 将docker.service 上傳到 /etc/systemd/system/ 目錄下
- 啟動
chmod +x /etc/systemd/system/docker.service #添加檔案權限并啟動docker
systemctl daemon-reload #重載unit配置檔案
systemctl start docker #啟動Docker
systemctl enable docker.service #設定開機自啟
- 重新開機docker
systemctl restart docker
- 驗證
systemctl status docker #檢視Docker狀态
docker -v #檢視Docker版本
- 離線版本解除安裝
'删除docker.service...'
rm -f /etc/systemd/system/docker.service
'删除docker檔案...'
rm -rf /usr/bin/docker*
'重新加載配置檔案'
systemctl daemon-reload
'解除安裝成功...'