Docker引擎離線安裝及集群配置
1. 下載對應二進制包
根據不同作業系統架構選擇,例如:
Linux CentOS7選擇:x86_64
https://download.docker.com/linux/static/stable/
2. 解壓
tar xzvf docker-19.03.4.tgz
3. 將解壓后的目錄復制到/usr/bin下
cp docker/* /usr/bin
4. 添加docker.service檔案
vi /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket
[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 fd://
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
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
5. 執行
chmod +x /etc/systemd/system/docker.service
6. 添加 docker.socket 檔案
vi /lib/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API
PartOf=docker.service
[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
7. 添加daemon.json檔案
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries": ["xxx.xxx.xxx.xxx:5000"],
"data-root": "/data/docker"
}
8. 啟動docker服務并設定開機自啟
systemctl daemon-reload
systemctl start docker
systemctl enable docker.service
至此docker安裝完畢,文章最后附有兩個常見錯誤處理方法,希望對大家有幫助,以下是配置集群方法
初始化集群:docker swarm init
在主節點服務器執行命令:docker swarm init,保存控制臺輸出的以下命令:
docker swarm join --token SWMTKN-1-1utny8u213o4varez63ptxru7iou5d8jzzimfehyxhk08yqqfk-65f4593hpdczbi70a58comcfv xxx.xxx.xxx.xxx:2377
在需要其他裝有docker的服務器上運行以上命令即可加入集群
錯誤處理
A dependency job for docker.service failed. See 'journalctl -xe' for details.
處理方法:給系統添加一個docker組:
groupadd docker
chattr -i /etc/group
systemctl enable docker && systemctl start docker
docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"write /proc/self/attr/keycreate: permission denied\"": unknown.
處理方法:
修改 /etc/selinux/config中SELINUX=disabled
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243953.html
標籤:其他
