#docker安装
#自写安装
debian
centos7
oracle
arm-debian10
centos9
arm-EulerOS2
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
echo "开始安装 docker-ce"
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 2>&1 > /dev/null
docker --version || ( echo "docker 安装失败" && exit )
# docker自动补全
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
sed -i '/^ExecStart=/cExecStart=/usr/bin/dockerd' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl restart docker
systemctl enable dockeryum -y install yum-utils device-mapper-persistent-data lvm2 bash-completion > /dev/null
# yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge
echo "${CMSG}开始 yum 安装 docker-ce${CEND}"
yum -y install docker-ce 2>&1 > /dev/null
docker --version || ( echo "${CWARNING}docker 安装失败${CEND}" && exit )
# docker自动补全
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
sed -i '/^ExecStart=/cExecStart=/usr/bin/dockerd' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl start docker
systemctl enable dockerdnf -y install dnf-utils device-mapper-persistent-data lvm2
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io --nobest --allowerasing
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
sed -i '/^ExecStart=/cExecStart=/usr/bin/dockerd' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl restart docker
systemctl enable dockerapt update
apt-get install net-tools telnet wget curl zip unzip tar perl tree expect git vim sysstat -y
apt-get install chrony locales -y
systemctl restart chrony
systemctl enable chrony
timedatectl set-timezone Asia/Shanghai
timedatectl set-local-rtc 0
apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
echo "deb [arch=arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
apt update
apt install docker-ce docker-ce-cli containerd.io -y
# 其他
cat << EOF > /etc/docker/daemon.json
{
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl enable dockermkdir -p /etc/yum.repos.d/backup/
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
cat << EOF > /etc/yum.repos.d/redhat.repo
[ali_baseos]
name=ali_baseos
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/
gpgcheck=0
[ali_appstream]
name=ali_appstream
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/
gpgcheck=0
EOF
yum install -y yum-utils
rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "Asia/Shanghai" > /etc/timezone
systemctl restart crond
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
sed -i '/^ExecStart=/cExecStart=/usr/bin/dockerd' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl restart docker
systemctl enable dockercat << EOF > /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - \$basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/\$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://download.docker.com/linux/centos/7/source/stable
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test]
name=Docker CE Test - \$basearch
baseurl=https://download.docker.com/linux/centos/7/\$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://download.docker.com/linux/centos/7/source/test
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
EOF
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
systemctl daemon-reload
systemctl start docker
systemctl enable docker#在线官方一键安装
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh#离线安装
x86
arm
# 源站下载地址 https://download.docker.com/linux/static/stable/x86_64/docker-28.1.1.tgz
# 国内镜像下载地址 https://mirrors.nju.edu.cn/docker-ce/linux/static/stable/x86_64/docker-28.1.1.tgz
tar -zxvf docker-28.1.1.tgz
mv docker/* /usr/bin/ -f
groupadd docker
cat << EOF > /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target nss-lookup.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
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
ExecReload=/bin/kill -s HUP \$MAINPID
TimeoutStartSec=0
RestartSec=2
Restart=always
# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3
# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s
# 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
# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity
# 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
OOMScoreAdjust=-500
[Install]
WantedBy=multi-user.target
EOF
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"hosts": ["unix:///var/run/docker.sock"],
"iptables": false,
"ipv6": false,
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
mkdir -p /usr/lib/systemd/system/
cat << EOF > /usr/lib/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API
[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF
systemctl daemon-reload
systemctl restart docker
systemctl enable docker# 源站下载地址 https://download.docker.com/linux/static/stable/aarch64/docker-28.1.1.tgz
# 国内镜像下载地址 https://mirrors.nju.edu.cn/docker-ce/linux/static/stable/aarch64/docker-28.1.1.tgz
# 解压二进制
tar -zxvf docker-28.1.1.tgz
mv docker/* /usr/bin/ -f
# 添加 docker 用户组
groupadd docker
# systemd service
cat << EOF > /etc/systemd/system/docker.service
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP \$MAINPID
LimitNOFILE=65535
LimitNPROC=65535
LimitCORE=65535
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
# 配置 daemon.json
mkdir -p /etc/docker/
cat << EOF > /etc/docker/daemon.json
{
"hosts": ["unix:///var/run/docker.sock"],
"iptables": false,
"ipv6": false,
"experimental": true,
"data-root": "/data/docker/",
"log-driver": "json-file",
"log-opts": {
"max-size": "500m",
"max-file": "10"
}
}
EOF
# docker.socket
cat << EOF > /etc/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
EOF
# 重载 systemd
systemctl daemon-reload
systemctl enable docker
systemctl enable docker.socket
systemctl start docker
#openeuler
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
sed -i 's#$releasever#7#g' /etc/yum.repos.d/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin