Docker的包和二进制安装
Docker 安装及基础
Docker 版本说明
官方网址: https://www.docker.com/
OS系统版本选择:
Docker 目前已经支持多种操作系统的安装运行,比如Ubuntu、CentOS、Redhat、Debian、Fedora,
甚至是还支持了Mac和Windows,在linux系统上需要内核版本在3.10或以上
Docker 版本选择:
github地址: https://github.com/moby/moby
Docker版本号之前一直是0.X版本或1.X版本,从2013年3月13日发布第一个版本0.1.1-1开始一直到2017
年02月08日发布1.13.1版
从2017年3月1号开始改为每个季度发布一次稳定版,其版本号规则也统一变更为YY.MM.xx,第一个版
本为17.03.0, 例如17.09表示是2017年9月份发布的
Docker之前没有区分版本,但是2017年推出(将docker更名为)新的项目Moby,Moby项目属于Docker
项目的全新上游,Docker将是一个隶属于的Moby的子产品,而且之后的版本之后开始区分为
CE(Docker Community Edition,社区版本)和 EE(Docker Enterprise Edition,企业收费版),CE
社区版本和EE企业版本都是每个季度发布一个新版本,但是EE版本提供后期安全维护1年,而CE版本是4
个月,以下为官方原文:
https://blog.docker.com/2017/03/docker-enterprise-edition/
如果要布署到 kubernetes上,需要查看相关kubernetes对docker版本要求的说明,比如
https://github.com/kubernetes/kubernetes/blob/v1.17.2/CHANGELOG-1.17.md
Docker 安装和删除
官方文档 : https://docs.docker.com/engine/install/
阿里云文档: https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11gu
HCWE
安装方法
- 内置仓库
- 官方仓库(国内镜像)
- 二进制安装(离线)
- 官方脚本
RHEL系统包安装和删除Docker
官方文档:
https://docs.docker.com/engine/install/centos/
https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11ziHbeh
RHEL系统 (使用 yum 进行安装)
# step 1: 安装必要的一些系统工具
sudo dnf install -y yum-utils
# 3. 添加 Docker 官方仓库
sudo dnf config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 4. 安装 Docker Engine
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
#因为国内无法访问docker官方镜像,需要配置docker访问docker官方镜像
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://docker.1panel.live",
"https://docker.1ms.run",
"https://docker.xuanyuan.me"
],
"insecure-registries": ["harbor.ming.org"]
}
EOF
# Step 4: 开启Docker服务
systemctl restart docker
systemctl enable docker
docker version
Linux 二进制离线安装
本方法适用于无法上网或无法通过包安装方式安装的主机上安装docker
安装文档:
https://docs.docker.com/engine/install/binaries/
https://docs.docker.com/install/linux/docker-ce/binaries/
二进制安装下载路径
https://download.docker.com/linux/
https://download.docker.com/linux/static/stable/
https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/
范例: 实现二进制安装dock
wget https://download.docker.com/linux/static/stable/x86_64/docker-29.3.1.tgz
tar xf docker-29.3.1.tgz
cp docker/* /usr/local/bin/
范例: 创建 service文件
[root@master2 ~]# cat /lib/systemd/system/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/local/bin/dockerd -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
systemctl daemon-reload
systemctl enable --now docker
systemctl status docker
docker version
范例:自动补全
# For Bash users
dnf install -y bash-completion
curl -L https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
bash
官方通用安装Docker脚本
从Docker官方下载通用安装脚本
注意: 此脚本当前不支持 Rocky Linux
如果是Rocky,修改os-release文件如下,即可支持安装
vim /etc/os-release
ID="centos"
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh --mirror Aliyun
Docker 配置和优化
https://docs.docker.com/reference/cli/dockerd/#daemon-configuration-file
注意:这种方式只对新建的容器有效的,之前的容器不生效
范例: 支持官方仓库和私有仓库镜像下载
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": [ "https://docker.m.daocloud.io", "https://docker.1panel.live", "https://docker.1ms.run", "https://docker.xuanyuan.me" ], "insecure-registries": ["harbor.ming.org"] } EOF
#只支持docker官方镜像
范例: Docker 优化
[root@ubuntu2404 ~]#vim /etc/docker/daemon.json { "registry-mirrors": [ "https://registry.docker-cn.com", "http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn", "https://si7y70hh.mirror.aliyuncs.com/" ], #开启远程:https://docs.docker.com/config/daemon/remote-access/ #方法1:docker.service文件中ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H fd:// #方法2: 注意:需要删除/lib/systemd/system/docker.service文件中的-H fd:// 两种冲突 "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"], "insecure-registries": ["harbor.wang.org"], "exec-opts": ["native.cgroupdriver=systemd"], "data-root": "/data/docker", #方法1:指定docker数据目录,方法2: ExecStart=/usr/bin/dockerd --data-root=/data/docker #"graph": "/data/docker", #旧版写法,指定docker数据目录,新版24.0.0不支持 "max-concurrent-downloads": 10, "max-concurrent-uploads": 5, "log-opts": { "max-size": "300m", #指定容器日志文件的最大值 "max-file": "2" #指定容器日志文件的个数,循环写入日志文件,即一个日志满,会写入第二 个文件 }, "live-restore": true, #docker.service重启,不影响容器的运行 "proxies": { #代理 https://docs.docker.com/network/proxy/ "default": { "httpProxy": "http://proxy.example.com:3128", "httpsProxy": "https://proxy.example.com:3129", "noProxy": "*.test.example.com,.example.org,127.0.0.0/8" } "tcp://docker-daemon1.example.com": { "noProxy": "*.internal.example.net" } } }
systemctl daemon-reload && systemctl restart docker.service
mkdir -p /data/docker
[root@master2 ~]# cat /lib/systemd/system/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/local/bin/dockerd -H unix:///var/run/docker.sock --data-root=/data/docker 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
systemctl daemon-reload && systemctl restart docker.service
浙公网安备 33010602011771号