SweetEriri

docker Cgroup无法挂载的解决办法

docker在系统重启后无法正常启动 通过dockerd直接运行发现报错

WARN[2020-09-16T15:43:26.703290910+08:00] Unable to find cpu cgroup in mounts

遂上网搜寻解决办法 发现了一个脚本 分享一下 (脚本源地址无法找到 保留了作者 可以在github上找到)

#!/bin/sh
# Copyright 2011 Canonical, Inc
#           2014 Tianon Gravi
# Author: Serge Hallyn <serge.hallyn@canonical.com>
#         Tianon Gravi <tianon@debian.org>
set -e

# for simplicity this script provides no flexibility

# if cgroup is mounted by fstab, don't run
# don't get too smart - bail on any uncommented entry with 'cgroup' in it
if grep -v '^#' /etc/fstab | grep -q cgroup; then
    echo 'cgroups mounted from fstab, not mounting /sys/fs/cgroup'
    exit 0
fi

# kernel provides cgroups?
if [ ! -e /proc/cgroups ]; then
    exit 0
fi

# if we don't even have the directory we need, something else must be wrong
if [ ! -d /sys/fs/cgroup ]; then
    exit 0
fi

# mount /sys/fs/cgroup if not already done
if ! mountpoint -q /sys/fs/cgroup; then
    mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
fi

cd /sys/fs/cgroup

# get/mount list of enabled cgroup controllers
for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
    mkdir -p $sys
    if ! mountpoint -q $sys; then
        if ! mount -n -t cgroup -o $sys cgroup $sys; then
            rmdir $sys || true
        fi
    fi
done

# example /proc/cgroups:
#  #subsys_name hierarchy   num_cgroups enabled
#  cpuset   2   3   1
#  cpu  3   3   1
#  cpuacct  4   3   1
#  memory   5   3   0
#  devices  6   3   1
#  freezer  7   3   1
#  blkio    8   3   1

exit 0

运行脚本后docker 可以正常启动


发表评论

评论列表,共 3 条评论

  • Diksdib
    https://jakjon.com/ Новый рейтинг казино онлайн с быстрой моментальной выплатой и супер большой отдачей. https://jakjon.com/ New online casino rating with fast instant payouts and super big returns.
  • Patrickpoive
    An ounce of prevention is worth a pound of cure. https://spirifij375.net A friend in need is a friend indeed Link to proverb. A leopard cannot change its spots Link to proverb. Don't upset the apple-cart Link to proverb. Put your shoulder to the wheel Link to proverb. More the merrier - The. The Devil is in the details Link to proverb.
  • Patrickpoive
    A golden key can open any door Link to proverb. https://spirifij375.net No rest for the wicked Link to proverb. Paddle your own canoe. April showers bring forth May flowers. The best-laid schemes of mice and men gang aft agley Link to proverb. Adversity makes strange bedfellows Link to proverb. Good man is hard to find - A.