天天看点

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是已经安装完成的文件夹)

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

5.2 执行脚本进行安装

$ bash install.sh docker.tgz      

    执行过程如下:

  待脚本执行完毕后,执行

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

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

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

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

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

-----------------------------------

作者:怒吼的萝卜

链接:http://www.cnblogs.com/nhdlb/

-----------------------------------