天天看点

二进制安装docker1. 下载docker二进制版本2. 解压出二进制文件3. 复制二进制文件到/usr/bin目录下4. 检查docker命令是否可用5. 配置systemctl 启动命令并设置开机启动6. 验证docker 是完成安装

有些场景不得不采用二进制安装docker,例如:客户内网机房环境。

本文参考官网文档: https://docs.docker.com/engine/install/binaries/#install-daemon-and-client-binaries-on-linux

1. 下载docker二进制版本

请选择最新最稳定的CE版本

https://download.docker.com/linux/static/stable/x86_64/

例如 :下载版本为18.06.3-ce的docker二进制压缩包到 /tmp目录下:

2. 解压出二进制文件

解压出的一个文件目录为 docker/

[[email protected] tmp]# tar -xvf docker-18.06.3-ce.tgz
[[email protected] tmp]# ls
docker  docker-18.06.3-ce.tgz

           

3. 复制二进制文件到/usr/bin目录下

4. 检查docker命令是否可用

[[email protected] tmp]# docker --version
Docker version 18.06.3-ce, build d7080c1

           

5. 配置systemctl 启动命令并设置开机启动

以上步骤安装成功后,shell命令行下 sudo dockerd & 即可启动docker,但一般我们采用 systemctl 方式启动docker服务并设置开机启动

创建 /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
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

           

采用 systemctl 设置自动重启

[[email protected] tmp]# systemctl daemon-reload
[[email protected] tmp]# systemctl start docker.service

# --------------设置开机自动启动-------------------
[[email protected] tmp]# sudo systemctl enable docker

           

6. 验证docker 是完成安装

[[email protected] tmp]# ps aux|grep docker
root       1828  0.7  2.5 637736 47572 ?        Ssl  18:39   0:01 /usr/bin/dockerd
root       1973  1.0  1.4 349884 26156 ?        Ssl  18:39   0:01 docker-containerd --config /var/run/docker/containerd/containerd.toml
root       2822  0.0  0.0  12108  1056 pts/0    S+   18:42   0:00 grep --color=auto docker

# 第一次运行该命令,本地镜像不存在,docker会自动从dockerhub上下载该镜像
[[email protected] tmp]# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/