Docker:Linux离线安装docker-17.03.2-ce,配置开机自启

1. 准备docker离线包

docker官方离线包下载地址

下载需要安装的docker版本,我此次下载的是:docker-17.03.2-ce.tgz

2. 准备docker.service 系统配置文件

创建docker.service

# vim 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

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

3. 准备安装脚本和卸载脚本

创建安装脚本:install.sh

# vim install.sh

内容如下:

#!/bin/sh
echo '解压tar包...'
tar -xvf $1
echo '将docker目录移到/usr/bin目录下...'
cp docker/* /usr/bin/
echo '将docker.service 移到/etc/systemd/system/ 目录...'
cp docker.service /etc/systemd/system/
echo '添加文件权限...'
chmod +x /etc/systemd/system/docker.service
echo '重新加载配置文件...'
systemctl daemon-reload
echo '启动docker...'
systemctl start docker
echo '设置开机自启...'
systemctl enable docker.service
echo 'docker安装成功...'
docker -v

4. 卸载docker脚本

创建卸载脚本:delete.sh

$ vim delete.sh

内容如下:

#!/bin/sh
echo '删除docker.service...'
rm -rf /etc/systemd/system/docker.service
echo '删除docker文件...'
rm -rf /usr/bin/docker*
echo '重新加载配置文件'
systemctl daemon-reload
echo '卸载成功...'

5. 安装docker

5.1 当前目录下的所有文件:(蓝色的docker是已经安装完成的文件夹)

5.2 执行脚本进行安装

$ bash install.sh docker.tgz

配置docker国内源

创建或修改 /etc/docker/daemon.json 文件,修改为如下形式

{
  "live-restore": true,
  "log-driver": "json-file",
  "log-opts": {
    "max-size":"500m",
    "max-file":"3",
    "env": "os,customer"
  },
  "bip": "10.0.1.1/24",
  "default-address-pools" : [
    {
      "base" : "10.0.1.0/16",
      "size" : 24
    }
   ],
    "registry-mirrors": [
        "https://docker-0.unsee.tech",
        "https://docker.1ms.run",
        "https://docker.xuanyuan.me",
        "https://0vrv861z.mirror.aliyuncs.com",
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com",
        "https://2a6bf1988cb6428c877f723ec7530dbc.mirror.swr.myhuaweicloud.com",
        "https://docker.m.daocloud.io",
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com",
        "https://your_preferred_mirror",
        "https://dockerhub.icu",
        "https://docker.registry.cyou",
        "https://docker-cf.registry.cyou",
        "https://dockercf.jsdelivr.fyi",
        "https://docker.jsdelivr.fyi",
        "https://dockertest.jsdelivr.fyi",
        "https://mirror.aliyuncs.com",
        "https://dockerproxy.com",
        "https://mirror.baidubce.com",
        "https://docker.m.daocloud.io",
        "https://docker.nju.edu.cn",
        "https://docker.mirrors.sjtug.sjtu.edu.cn",
        "https://docker.mirrors.ustc.edu.cn",
        "https://mirror.iscas.ac.cn",
        "https://docker.rainbond.cc"
      ]
}

待脚本执行完毕后,执行

//查看docker版本命令
$ docker -v

发现此时docker已安装成功,可以用

//查看docker所有命令
$ docker --help 

从现在开始你就可以自己安装image和生成container了

 

文章转载至:https://www.jb51.net/article/167103.htm

posted @ 2019-06-12 16:46  怒吼的萝卜  阅读(1102)  评论(0)    收藏  举报