Docker安装
简介
文件以{}包裹为变量,请按照实际内容替换
例如 tar -xvf {docker}.tgz 中的变量docker为具体的文件名
本文中搭建集群使用的是 Portainer
在线安装
需要注意的是需要先卸载Docker的遗留安装(如果有的话)
centos ,Unbantu 等平台的安装方式略有不同
离线安装
选择合适的版本下载
- 解压缩
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
首次登录需要设置账号密码,点击确认即可
选择Poratiner运行方式,有四种选项
- 管理本地docker
- 管理远程docker
- 通过Portainer-Agent管理
- 微软Azure环境
选择本地docker即可,点击connect进入仪表盘,可以看到本地节点Primary
可以添加集群的节点,从而通过Portainer管理工具进行管理。