二 安装 Docker
1 环境
1.1 测试环境(Docker 1.7.1(2015-07-14))
$ docker version
Client version: 1.7.1(2015-07-14)
Client API version: 1.19
Server version: 1.7.1(2015-07-14)
Server API version: 1.19
https://docs.docker.com/engine/release-notes/prior-releases/#171-2015-07-14
这版本都是 2015 年的版本了。。。。
1.2 线上环境(Docker 20.10.5)
docker version
Client: Docker Engine - Community
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:17:04 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.5
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 363e9a8
Built: Tue Mar 2 20:15:27 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.4
GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc:
Version: 1.0.0-rc93
GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
docker-init:
Version: 0.19.0
GitCommit: de40ad0
2 docker 安装
2.1 bin 安装
https://download.docker.com/linux/static/stable/x86_64/
从官网下载压缩包
解压到 /usr/bin
在解压目录执行 dockerd,即可启动
$ curl "https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz" -o docker-20.10.9.tgz
解压之后就是如下文件
$ ll docker
total 401680
-rwxr-xr-x@ 1 wangbin34 staff 33908392 10 5 2021 containerd
-rwxr-xr-x@ 1 wangbin34 staff 6508544 10 5 2021 containerd-shim
-rwxr-xr-x@ 1 wangbin34 staff 8609792 10 5 2021 containerd-shim-runc-v2
-rwxr-xr-x@ 1 wangbin34 staff 21131264 10 5 2021 ctr
-rwxr-xr-x@ 1 wangbin34 staff 52883616 10 5 2021 docker
-rwxr-xr-x@ 1 wangbin34 staff 708616 10 5 2021 docker-init
-rwxr-xr-x@ 1 wangbin34 staff 2784145 10 5 2021 docker-proxy
-rwxr-xr-x@ 1 wangbin34 staff 64758736 10 5 2021 dockerd
-rwxr-xr-x@ 1 wangbin34 staff 14352296 10 5 2021 runc
2.2 rpm 安装
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
containerd.io-1.6.9-3.1.el7.x86_64.rpm
docker-ce-20.10.24-3.el7.x86_64.rpm
docker-ce-cli-20.10.24-3.el7.x86_64.rpm
docker-ce-rootless-extras-20.10.24-3.el7.x86_64.rpm
yum -y install containerd.io-1.6.9-3.1.el7.x86_64.rpm
yum -y install docker-ce-cli-20.10.24-3.el7.x86_64.rpm
yum -y install docker-ce-20.10.24-3.el7.x86_64.rpm docker-ce-rootless-extras-20.10.24-3.el7.x86_64.rpm
3 docker 启动参数
/usr/bin/dockerd --containerd=/run/containerd/containerd.sock --registry-mirror http://registry.baidubce.com --insecure-registry registry.baidubce.com -H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock --selinux-enabled=false --live-restore=true --log-opt max-size=100m --log-opt max-file=5 --max-concurrent-downloads=50 --max-concurrent-uploads=50 --userland-proxy=false --log-level=debug --data-root=/mnt/docker/data --exec-root=/mnt/docker/exec --iptables=false
3.1 centos8 启动文件
3.1.1 containerd
/usr/lib/systemd/system/containerd.service
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# 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
LimitNOFILE=1048576
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
3.1.2 docker
/usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service
[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:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock \
--registry-mirror http://registry.baidubce.com \
--insecure-registry registry.baidubce.com \
-H tcp://127.0.0.1:4243 \
-H unix:///var/run/docker.sock \
--selinux-enabled=false \
--live-restore=true \
--log-opt max-size=100m \
--log-opt max-file=5 \
--max-concurrent-downloads=50 \
--max-concurrent-uploads=50 \
--userland-proxy=false \
--log-level=debug \
--data-root=/mnt/docker/data \
--exec-root=/mnt/docker/exec \
--iptables=false \
--bridge=none \
--ip-forward=false \
--ip-masq=false
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=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.
LimitNOFILE=infinity
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
配置文件(/etc/docker/daemon.json) ---- 忽略(启动文件时,会加载 /etc/docker/daemon.json, 目前已配置到 docker.service 中)
{
"bridge": "none",
"ip-forward": false,
"ip-masq": false,
"data-root": "/home/work/docker/data",
"exec-root": "/home/work/docker/exec"
}
data-root 和 exec-root 需要是个非软链目录,否则启动容器时会失败
3.2 Ceontos6.3 启动文件
/etc/init.d/docker
#!/bin/sh
#
# /etc/rc.d/init.d/docker
#
# Daemon for docker.com
#
# chkconfig: 2345 95 95
# description: Daemon for docker.com
### BEGIN INIT INFO
# Provides: docker
# Required-Start: $network cgconfig
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop docker
# Description: Daemon for docker.com
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Adapt to Baidu Deck
[[ -s "/home/opt/deck/etc/bashrc" ]] && source "/home/opt/deck/etc/bashrc"
prog="docker"
bin_dir="/usr/bin"
exec="${bin_dir}/dockerd --containerd=/run/containerd/containerd.sock \
-H tcp://127.0.0.1:4500 \
-H unix:///var/run/docker.sock \
--selinux-enabled=false \
--live-restore=true \
--log-opt max-size=100m \
--log-opt max-file=5 \
--max-concurrent-downloads=50 \
--max-concurrent-uploads=50 \
--userland-proxy=false \
--log-level=debug \
--data-root=/ssd1/data/docker/data \
--exec-root=/ssd1/data/docker/exec \
--iptables=false \
--bridge=none \
--ip-forward=false \
--ip-masq=false"
pidfile="/var/run/$prog.pid"
lockfile="/var/lock/subsys/$prog"
logfile="/var/log/$prog"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
prestart() {
service cgconfig status > /dev/null
if [[ $? != 0 ]]; then
service cgconfig start
fi
}
start() {
check_for_cleanup
check_containerd
if ! [ -f $pidfile ]; then
prestart
printf "Starting $prog:\t"
echo "\n$(date)\n" >> $logfile
$exec &>> $logfile &
pid=$!
touch $lockfile
# wait up to 10 seconds for the pidfile to exist. see
# https://github.com/docker/docker/issues/5359
tries=0
while [ ! -f $pidfile -a $tries -lt 10 ]; do
sleep 1
tries=$((tries + 1))
done
success
echo
else
failure
echo
printf "$pidfile still exists...\n"
exit 7
fi
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile -d 300 $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
status -p $pidfile $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
check_for_cleanup() {
if [ -f ${pidfile} ]; then
/bin/ps -fp $(cat ${pidfile}) > /dev/null || rm ${pidfile}
fi
}
check_containerd() {
PROC_COUNT=$(ps -ef | grep ${bin_dir}/containerd | grep -vc grep)
if [ $PROC_COUNT \> 0 ]; then
return
fi
${bin_dir}/containerd 1>>$logfile 2>&1 &
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
chmod +x /etc/init.d/docker
使用 deck 部署时,需要将 bin_dir 改为 "/home/opt/deck/1.0/docker/20.10.17/bin"
4 子目录
Last updated