docker & docker-compose 离线安装

Docker 专栏收录该内容
50 篇文章 3 订阅

Docker 离线安装的方法,其实官方已经给出了很明确的步骤。
官网链接
安装包下载地址
本文当前docker最新版:docker-19.03.3.tgz
docker-compose:1.24.1

其主要内容如下:

Install static binaries

  1. Download the static binary archive. Go to https://download.docker.com/linux/static/stable/ (or change stable to nightly or test), choose your hardware platform, and download the .tgz file relating to the version of Docker Engine - Community you want to install.

  2. Extract the archive using the tar utility. The dockerd and docker binaries are extracted.

	$ tar xzvf /path/to/<FILE>.tar.gz
  1. Optional: Move the binaries to a directory on your executable path, such as /usr/bin/. If you skip this step, you must provide the path to the executable when you invoke docker or dockerd commands.
	$ sudo cp docker/* /usr/bin/
  1. Start the Docker daemon:
	$ sudo dockerd &

If you need to start the daemon with additional options, modify the above command accordingly or create and edit the file /etc/docker/daemon.json to add the custom configuration options.

  1. Verify that Docker is installed correctly by running the hello-world image.
	$ sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

配置docker为系统服务的具体操作如下三步

这里要注意了:按上面的方法确实可以正常安装和使用docker,按命令 sudo dockerd & 启动可以满足基本使用,但是docker 从1.11开始已经不是简单的通过Docker daemon来启动,而是集成了containerd、runC等多个组件。

按照如下步骤,我们先配置 containerd,再配置 docker.socket,然后配置 docker.service 服务:

一、配置 containerd

mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
touch /usr/lib/systemd/system/containerd.service
vi /usr/lib/systemd/system/containerd.service

containerd.service 内容如下:

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target

[Service]
ExecStartPre=/sbin/modprobe overlay
ExecStart=/usr/bin/containerd  # 这是你 containerd  文件的放置路径
Delegate=yes
KillMode=process
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity

[Install]
WantedBy=multi-user.target

执行下面的命令启动 containerd 服务并查看服务的状态:

$ sudo systemctl daemon-reload
$ sudo systemctl enable containerd.service
$ sudo systemctl start containerd.service
$ sudo systemctl status containerd.service

二、配置 docker.socket

groupadd docker
touch /usr/lib/systemd/system/docker.socket
vi /usr/lib/systemd/system/docker.socket

docker.socket 文件内容如下:

[Unit]
Description=Docker Socket for the API
PartOf=docker.service

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
# 如果出现错误:chown socket at step GROUP: No such process, 可以修改下面的 SocketGroup=root 或创建 docker 用户组(命令 groupadd docker)
SocketGroup=docker

[Install]
WantedBy=sockets.target

执行下面的命令启动 containerd 服务并查看服务的状态:

$ sudo systemctl daemon-reload
$ sudo systemctl enable containerd.service
$ sudo systemctl start containerd.service
$ sudo systemctl status containerd.service

服务的 unmask 解禁操作(禁用是 mask,被禁用的服务手工启动服务和重启机器是都拉不起服务的)

systemctl unmask docker.service
systemctl unmask docker.socket

三、配置 docker.service 服务

touch /usr/lib/systemd/system/docker.service
vi /usr/lib/systemd/system/docker.service

docker.service 文件内容如下:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket

[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 -H fd:// --containerd=/run/containerd/containerd.sock 
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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

[Install]
WantedBy=multi-user.target

然后执行下面命令载入服务:

chmod +x /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl enable docker
systemctl start docker

安装 docker-compose

下载(docker-compose-Linux-x86_64):docker-compose 官网下载地址

然后操作拷贝和可执行权限并查看版本

sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose 
sudo chmod +x /usr/local/bin/docker-compose
docker-compose -v

(THE END)

  • 3
    点赞
  • 0
    评论
  • 9
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 猿与汪的秘密 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值