通过二进制安装的 Docker 怎么设置 daemon.json 配置文件

一、引言

安装 Docker 有很多种方式,其中使用二进制的方式离线安装 Docker 无亦是最简单的一种。

然而简单的后果带来的是与其他安装方式不同的配置方式。

比如说,当你作为 Docker 客户端,想要推送本地的镜像到私有镜像库的时候。此时会出现这么一个问题:

The push refers to repository [192.168.0.201:5000/ubuntu]
INFO[2018-05-25T01:35:53.003377576-07:00] Attempting next endpoint for push after error: Get https://192.168.0.201:5000/v2/: http: server gave HTTP response to HTTPS client
Get https://192.168.0.201:5000/v2/: http: server gave HTTP response to HTTPS client

这里就需要 Docker 客户端自己配置一个 daemon.json 文件,将其设置为下述内容:

{
  "insecure-registries": [ "192.168.0.201:5000"] # 这是我虚拟机中的配置
}

然而,通过二进制安装的 Docker,在 /etc/docker 下并没有 daemon.json 文件,这下该怎么办呢?

二、问题解决

其实这个问题,在官方文档中有提到过 Install Docker CE from binaries

  1. Start the Docker daemon:
    $ sudo dockerd &
    If you need to start the daemon with addtional options, modify the above command accordingly or create and edit the file /etc/docker/daemon.json to add the custom configuration options.

也就是说,我们要么自己指定 daemon.json 的位置,要么就按照默认的路径 /etc/docker 来就行。

因此这个问题有两个方式解决:

1. 根据 dockerd 官方文档 dockerd | Docker Document:

–config-file string Daemon configuration file (default “/etc/docker/daemon.json”)

也就是说,我们可以通过:

$ sudo dockerd --config-file=xxx

来指定自己的 daemon.json 的位置

2. 直接按照 daemon.json 的默认位置,没有该文件也直接自己新建一个即可

问题解决就是这么简单:)

Enjoy It ^_^

猜你喜欢

转载自blog.csdn.net/u012814856/article/details/80454163