Centos7离线安装Docker

工做缘由须要在客户现场离线安装docker,网上看了不少,官方文档也查了一下,总结以下:linux

(已在客户现场成功安装,Centos7,其余linux版本没试过,感受应该问题不大)docker

1. 下载离线安装包bash

    提早找一台能上网的机器下载好离线安装包服务器

    地址:https://download.docker.com/linux/static/stable/app

    选择合适本身的版本。我这里用的是x86-64/docker-18.03.1-ce.tgzui

2. 安装this

    安装包上传至服务器,解压缩:spa

tar -zxvf docker-18.03.1-ce.tgz

    解压缩后的文件拷贝到对应目录:rest

cp docker/* /usr/bin/

3.注册docker服务日志

    新建一个文件vi 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

将docker.service 拷贝到对应目录下:

cp docker.service /usr/lib/systemd/system/

4.启动和验证

    启动docker服务:    

systemctl start docker

    验证是否成功:

##这里就比较随意,用一些经常使用的docker命令
docker -v
docker --help

5. docker 经常使用命令

# 查看docker 镜像
docker images
# 查看docker全部容器
docker ps -a
# 运行中的容器
docker ps
# 运行一个新容器
docker run
# 启动|中止|重启 已经存在的容器
docker start|stop|restart 
# 导出镜像
docker save –o myapp.tar imageName (–o输出到文件)
# 导入镜像
docker load –i myapp.tar
# 删除镜像
docker rmi [镜像名称或ID]
# 删除容器
docker rm [容器名称]
# 进入容器
docker exec –it [容器名称] /bin/bash
# 查看容器日志
docker logs –f [容器名称]
相关文章
相关标签/搜索