linux环境离线安装docker

 安装包官方地址:https://download.docker.com/linux/static/stable/x86_64/

注:具体版本需要查看CPU架构

可以先下载到本地,然后通过ftp工具上传到服务器上,或者在服务器上使用命令下载

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz

tar -zxvf docker-18.06.3-ce.tgz

cp docker/* /usr/bin/

在/etc/systemd/system/目录下新增docker.service文件,内容如下,这样可以将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/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
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

启动docker

给docker.service文件添加执行权限

chmod +x /etc/systemd/system/docker.service ​​​​​​​
重新加载配置文件(每次有修改docker.service文件时都要重新加载下)
systemctl daemon-reload                
启动
systemctl start docker
设置开机启动
systemctl enable docker.service
查看docker服务状态
systemctl status docker

二、Ubuntu自动安装

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

apt-get install docker.io

本文安装的 docker 版本为 18.09.7。
执行如下命令新建 /etc/docker/daemon.json 文件:

cat > /etc/docker/daemon.json <<-EOF
{
  "registry-mirrors": [
    "https://a8qh6yqv.mirror.aliyuncs.com",
    "http://hub-mirror.c.163.com"
  ],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF


注:
registry-mirrors 为镜像加速器地址。
native.cgroupdriver=systemd 表示使用的 cgroup 驱动为 systemd(k8s 使用此方式),默认为 cgroupfs。修改原因是 kubeadm.conf 中修改k8s的驱动方式不成功。

重启docker,查看 cgroup:

# systemctl restart docker 
# docker info | grep -i cgroup
Cgroup Driver: systemd

出现 systemd 表示修改成功
 

 

注:在CFast卡制作的文件系统时,每次机开机重启时启动docker失败,报错:localhost dockerd[609]: crypto/rand: blocked for 60 seconds waiting to read random data from the kernel。

解决办法:

sudo apt-get install haveged
# 启动
systemctl start haveged

# 开机自启动
systemctl enable haveged

 

 

 

Guess you like

Origin blog.csdn.net/ggggyj/article/details/104921836