linux安装离线docker包教程,Centos7离线安装Docker

2022年6月6日10:08:17

工作原因需要在客户现场离线安装docker,网上看了很多,官方文档也查了一下,总结如下:

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

1. 下载离线安装包

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

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

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

2. 安装

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

tar -zxvf docker-18.03.1-ce.tgz

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

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 [容器名称]

来源:oschina

链接:https://my.oschina.net/u/3477333/blog/3081526

  • 作者:安世亚太
  • 原文链接:https://blog.csdn.net/weixin_31869579/article/details/116839902
    更新时间:2022年6月6日10:08:17 ,共 1840 字。