Docker安裝
簡介
檔案以{}包裹為變量,請按照實際内容替換
例如 tar -xvf {docker}.tgz 中的變量docker為具體的檔案名
本文中搭建叢集使用的是 Portainer複制代碼
線上安裝
需要注意的是需要先解除安裝Docker的遺留安裝(如果有的話)
centos ,Unbantu 等平台的安裝方式略有不同複制代碼
離線安裝
下載下傳docker
選擇合适的版本下載下傳複制代碼
- 解壓縮
tar -xvf {docker}.tgz複制代碼
- 移動檔案
cp docker/* /usr/bin/複制代碼
- 注冊服務
vi /etc/systemd/system/docker.service複制代碼
- 配置服務,把一下内容添加到docker.service中儲存
如果出現permission denied 請确認是否有該目錄的權限
需要注意參數ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
指定開啟TCP連接配接,并且指定資料卷為 /var/run/docker.sock 主管理節點不需要開啟TCP
- 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 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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複制代碼
- 添加目錄權限
chmod +x /etc/systemd/system/docker.service複制代碼
- 重載配置
systemctl daemon-reload複制代碼
- 啟動docker
systemctl start docker
複制代碼
- 驗證docker啟動狀态
systemctl status docker複制代碼
- 确認安裝docker版本是否一緻
docker -v
複制代碼
- 開啟2375端口
/sbin/iptables -I INPUT -p tcp --dport 2375 -j ACCEPT複制代碼
搭建Portainer(主管理節點)
- 建立資料卷
docker volume create portainer_data複制代碼
- 首次啟動Portainer
docker run -d -p 9000:9000 --name=portainer --restart=always -v
/var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer複制代碼
- 關閉&啟動容器
# 關閉
docker container stop portainer
# 啟動
docker container start portainer複制代碼
docker volume create portainer_data複制代碼
- 導入
docker load -i /xxxx/portainer.tar複制代碼
- 啟動 Portainer
docker run -d -p 9000:9000 --name=portainer --restart=always -v
/var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer複制代碼
- 驗證是否啟動成功
docker ps複制代碼
- 線上配置
登入主管理節點
通路http://{管理節點IP}:9000
複制代碼
首次登入需要設定賬号密碼,點選确認即可
- 管理本地docker
- 管理遠端docker
- 通過Portainer-Agent管理
- 微軟Azure環境