linux离线安装docker与compose

简介: linux离线安装docker与compose

前言

官方提供免安装的二进制程序包,解压后就能用。

PS1: docker基于iptables做路由转发,所以亲测debian11上需要先安装iptables(apt install -y iptables)

docker安装步骤

  1. 官网下载安装包。
  2. 解压安装包,将安装包内的二进制程序解压到/usr/local/bin目录。
  3. 建立docker的数据存放目录:
mkdir -p /home/data/docker
  1. 创建docker的service文件(/usr/lib/systemd/system/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/local/bin/dockerd --data-root /home/data/docker
 
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
  1. 使配置生效
systemctl daemon-reload
systemctl start docker
systemctl enable docker
  1. 验证
docker info

docker-compose安装步骤

  1. 官网下载二进制程序包
  2. 重命名为docker-compose,并移到/usr/local/bin
  3. 验证
docker-compose --version

配置docker的daemon.json

  • vim /etc/docker/daemon.json(检查格式:cat /etc/docker/daemon.json | python -m json.tool
{
    "exec-opts": [
        "native.cgroupdriver=systemd"
    ],
    "log-driver": "json-file",
    "log-level": "warn",
    "log-opts": {
        "max-size": "100m"
    },
    "storage-driver": "overlay2",
    "storage-opts": [
        "overlay2.override_kernel_check=true"
    ],
    "registry-mirrors": [
        "https://sral7lkb.mirror.aliyuncs.com"
    ],
    "ip-forward": true,
    "ip-masq": false,
    "iptables": false,
    "ipv6": false,
    "live-restore": true,
    "selinux-enabled": false,
    "bip": "172.17.200.1/24",
    "data-root": "/home/data/docker"
}

官方完全示例

{
  "allow-nondistributable-artifacts": [],
  "api-cors-header": "",
  "authorization-plugins": [],
  "bip": "",
  "bridge": "",
  "cgroup-parent": "",
  "containerd": "/run/containerd/containerd.sock",
  "containerd-namespace": "docker",
  "containerd-plugin-namespace": "docker-plugins",
  "data-root": "",
  "debug": true,
  "default-address-pools": [
    {
      "base": "172.30.0.0/16",
      "size": 24
    },
    {
      "base": "172.31.0.0/16",
      "size": 24
    }
  ],
  "default-cgroupns-mode": "private",
  "default-gateway": "",
  "default-gateway-v6": "",
  "default-runtime": "runc",
  "default-shm-size": "64M",
  "default-ulimits": {
    "nofile": {
      "Hard": 64000,
      "Name": "nofile",
      "Soft": 64000
    }
  },
  "dns": [],
  "dns-opts": [],
  "dns-search": [],
  "exec-opts": [],
  "exec-root": "",
  "experimental": false,
  "features": {},
  "fixed-cidr": "",
  "fixed-cidr-v6": "",
  "group": "",
  "hosts": [],
  "proxies": {
    "http-proxy": "http://proxy.example.com:80",
    "https-proxy": "https://proxy.example.com:443",
    "no-proxy": "*.test.example.com,.example.org",
  },
  "icc": false,
  "init": false,
  "init-path": "/usr/libexec/docker-init",
  "insecure-registries": [],
  "ip": "0.0.0.0",
  "ip-forward": false,
  "ip-masq": false,
  "iptables": false,
  "ip6tables": false,
  "ipv6": false,
  "labels": [],
  "live-restore": true,
  "log-driver": "json-file",
  "log-level": "",
  "log-opts": {
    "cache-disabled": "false",
    "cache-max-file": "5",
    "cache-max-size": "20m",
    "cache-compress": "true",
    "env": "os,customer",
    "labels": "somelabel",
    "max-file": "5",
    "max-size": "10m"
  },
  "max-concurrent-downloads": 3,
  "max-concurrent-uploads": 5,
  "max-download-attempts": 5,
  "mtu": 0,
  "no-new-privileges": false,
  "node-generic-resources": [
    "NVIDIA-GPU=UUID1",
    "NVIDIA-GPU=UUID2"
  ],
  "oom-score-adjust": 0,
  "pidfile": "",
  "raw-logs": false,
  "registry-mirrors": [],
  "runtimes": {
    "cc-runtime": {
      "path": "/usr/bin/cc-runtime"
    },
    "custom": {
      "path": "/usr/local/bin/my-runc-replacement",
      "runtimeArgs": [
        "--debug"
      ]
    }
  },
  "seccomp-profile": "",
  "selinux-enabled": false,
  "shutdown-timeout": 15,
  "storage-driver": "",
  "storage-opts": [],
  "swarm-default-advertise-addr": "",
  "tls": true,
  "tlscacert": "",
  "tlscert": "",
  "tlskey": "",
  "tlsverify": true,
  "userland-proxy": false,
  "userland-proxy-path": "/usr/libexec/docker-proxy",
  "userns-remap": ""
}

补充

  • 普通用户如需使用二进制方式安装的docker,可参考以下步骤。假设普通用户的用户名为admin
# 1. 创建docker用户组
groupadd docker
# 2. 将admin用户加到docker用户组
usermod admin -a -G docker
# 3. 重启docker
systemctl restart docker
# 4. admin用户执行docker命令进行测试

参考

相关文章
|
17天前
|
资源调度 关系型数据库 MySQL
docker制作compose
本文介绍了Docker Compose的基本使用,包括安装、创建`docker-compose.yml`文件定义服务,以及如何使用环境变量和卷来配置多容器应用的步骤。
16 1
docker制作compose
|
6天前
|
Ubuntu Linux 网络安全
Docker&Docker Compose安装(离线+在线)
Docker&Docker Compose安装(离线+在线)
65 1
|
1月前
|
关系型数据库 MySQL Linux
Linux 安装 mysql 【使用 tar.gz | tar.xz安装包-离线安装】
在Linux系统中使用tar.xz压缩包安装MySQL数据库的详细步骤。包括下载MySQL压缩包,解压到指定目录,创建mysql用户和组,设置目录权限,初始化MySQL,配置my.cnf文件,启动服务,以及修改root用户密码。此外,还提供了如何设置Windows远程登录MySQL服务器的方法。
Linux 安装 mysql 【使用 tar.gz | tar.xz安装包-离线安装】
|
13天前
|
存储 Kubernetes 持续交付
Docker Compose
【10月更文挑战第3天】
31 6
|
10天前
|
存储 Kubernetes 调度
掌握 Docker Compose
【10月更文挑战第6天】
14 1
|
19天前
|
开发者 Docker 微服务
利用Docker Compose优化微服务架构
在微服务架构中,Docker Compose提供了一种简便有效的方法来定义和运行多容器Docker应用程序,通过YAML文件配置服务、网络和卷,实现一键创建和启动。这不仅确保了开发、测试和生产环境的一致性,还简化了团队协作和维护工作,大幅提升了开发效率。本文将详细介绍Doker Compose的核心优势、基本使用方法及高级功能,帮助你更好地管理和优化微服务架构。
|
19天前
|
Docker 容器
利用Docker Compose优化开发环境的配置
在现代软件开发中,环境一致性至关重要。开发人员常需在不同机器间复制环境配置,而Docker Compose提供了一种简便有效的方法来定义和运行多容器Docker应用程序,确保开发、测试和生产环境一致,简化团队协作,提高开发效率。通过YAML文件配置服务、网络和卷,使用简单命令即可启动和停止服务。本文将介绍Docker Compose的核心优势、基本使用方法及高级功能,帮助你更好地管理和优化开发环境。
|
20天前
|
运维 数据库 开发者
docker回顾--docker compose详细解释,安装,与常用命令
docker回顾--docker compose详细解释,安装,与常用命令
|
22天前
|
存储 应用服务中间件 nginx
Docker Compose
【10月更文挑战第05天】
33 3
|
29天前
|
Docker Python 容器
python检测docker compose文件是否正确
python检测docker compose文件是否正确