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环境