许多国产化项目部署需要用到docker,而服务器有必须处于离线状态,那么离线安装docker就成为了一个问题,离线安装docker本身并不难,难的是安装docker的依赖软件。
经过多次尝试,依赖软件也没有安装成功,在一筹莫展之际,在docker官网看到,有一种离线安装方式叫:static binaries
1,下载离线静态包:https://download.docker.com/linux/static/stable/
2,执行命令:
1 sudo cp docker/* /usr/bin/
2 sudo dockerd &
正常只要进行上述两个步骤就可以成功了,但是还是遇到了一些问题。
1,failed to start daemon: Devices cgroup isn‘t mounted
这个是因为默认的cgroup的cpu,memory等没有被挂载,需要使用一个脚本来挂载,具体使用脚本是
1 #!/bin/sh
2 # Copyright 2011 Canonical, Inc
3 # 2014 Tianon Gravi
4 # Author: Serge Hallyn <serge.hallyn@canonical.com>
5 # Tianon Gravi <tianon@debian.org>
6 set -e
7
8 # for simplicity this script provides no flexibility
9
10 # if cgroup is mounted by fstab, don‘t run
11 # don‘t get too smart - bail on any uncommented entry with ‘cgroup‘ in it
12 if grep -v ‘^#‘ /etc/fstab | grep -q cgroup; then
13 echo ‘cgroups mounted from fstab, not mounting /sys/fs/cgroup‘
14 exit 0
15 fi
16
17 # kernel provides cgroups?
18 if [ ! -e /proc/cgroups ]; then
19 exit 0
20 fi
21
22 # if we don‘t even have the directory we need, something else must be wrong
23 if [ ! -d /sys/fs/cgroup ]; then
24 exit 0
25 fi
26
27 # mount /sys/fs/cgroup if not already done
28 if ! mountpoint -q /sys/fs/cgroup; then
29 mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
30 fi
31
32 cd /sys/fs/cgroup
33
34 # get/mount list of enabled cgroup controllers
35 for sys in $(awk ‘!/^#/ { if ($4 == 1) print $1 }‘ /proc/cgroups); do
36 mkdir -p $sys
37 if ! mountpoint -q $sys; then
38 if ! mount -n -t cgroup -o $sys cgroup $sys; then
39 rmdir $sys || true
40 fi
41 fi
42 done
43
44 # example /proc/cgroups:
45 # #subsys_name hierarchy num_cgroups enabled
46 # cpuset 2 3 1
47 # cpu 3 3 1
48 # cpuacct 4 3 1
49 # memory 5 3 0
50 # devices 6 3 1
51 # freezer 7 3 1
52 # blkio 8 3 1
53
54 # enable cgroups memory hierarchy, like systemd does (and lxc/docker desires)
55 # https://github.com/systemd/systemd/blob/v245/src/core/cgroup.c#L2983
56 # https://bugs.debian.org/940713
57 if [ -e /sys/fs/cgroup/memory/memory.use_hierarchy ]; then
58 echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
59 fi
60
61 exit 0
2,failed to create NAT chain DOCKER: iptables failed
docker的运行依赖于iptables,利用其中的nat功能
下载iptables:http://mirrors.ustc.edu.cn/debian/pool/main/i/iptables/
安装即可。
原文:https://www.cnblogs.com/guanghe/p/14807884.html