Docker-使用SystemD和“ daemon.json”启用远程HTTP API [英] Docker - Enable Remote HTTP API with SystemD and "daemon.json"

查看:276
本文介绍了Docker-使用SystemD和“ daemon.json”启用远程HTTP API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将Ubuntu 14.04与Upstart作为初始化系统的旧计算机上,我已通过定义 DOCKER_OPTS / etc / default / docker 上的c $ c>。

On a old machine with Ubuntu 14.04 with Upstart as init system I have enabled the HTTP API by defining DOCKER_OPTS on /etc/default/docker. It works.

$ docker version
Client:
 Version:      1.11.2
 (...)

Server:
 Version:      1.11.2
 (...)






问题:



此解决方案在具有以下功能的最新计算机上不起作用带有SystemD的Ubuntu 16.04。


Problem:

This does solution does not work on a recent machine with Ubuntu 16.04 with SystemD.

如最近安装的文件 / etc / default / docker 所述:

As stated on the top of the recent file installed /etc/default/docker:

# Docker Upstart and SysVinit configuration file

#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
#   Please see the documentation for "systemd drop-ins":
#   https://docs.docker.com/engine/articles/systemd/
#
(...)

当我在 SystemD的Docker文档页面我需要填写 daemon.json 文件,但在引用有些属性不言自明,但其他属性可能无法解释。

As I checked this information on the Docker documentation page for SystemD I need to fill a daemon.json file but as stated on the reference there are some properties self-explanatory but others could be under-explained.

话虽这么说,我正在寻求帮助以将其转换:

That being said, I'm looking for help to convert this:

DOCKER_OPTS =-H tcp://0.0.0.0:2375 -H Unix:///var/run/docker.sock -G myuser --debug

daemon.json 对象?

PS1:我知道 daemon.json debug:默认为true

PS2:可能是组: myuser 可以像这样或使用字符串数组来工作。

PS2: Probably the group: "myuser" it will work like this or with an array of strings.

PS3:我主要关心的是可以同时使用SOCK和HTTP。

PS3: My main concern is to use SOCK and HTTP simultaneous.

编辑(8/08/2017)
阅读接受的答案后,请检查@white_gecko答案以获取有关此问题的更多输入。

EDIT (8/08/2017) After reading the accepted answer, check the @white_gecko answer for more input on the matter.

推荐答案

由于文档分散,很难解决这个问题。

With a lot of fragmented documentation it was difficult to solve this.

我的第一个解决方案是使用

My first solution was to create the daemon.json with

{
  "hosts": [
    "unix:///var/run/docker.sock",
    "tcp://127.0.0.1:2376"
  ]
}

此错误不起作用 docker [5586] :尝试使用 service docker restart 重新启动守护程序后,无法使用文件/etc/docker/daemon.json 配置Docker守护程序。
注意:还有很多我无法复制的错误。

This does not worked this error docker[5586]: unable to configure the Docker daemon with file /etc/docker/daemon.json after tried to restart the daemon with service docker restart. Note: There was more on the error that I failed to copy.

但是此错误在启动守护程序时意味着它与标志冲突。和 daemon.json 上的配置。

But what this error meant it at the start the daemon it a conflict with a flag and configurations on daemon.json.

当我使用 service docker status对其进行调查时这是父进程: ExecStart = / usr / bin / docker守护程序-H fd://

When I looked into it with service docker status this it was the parent process: ExecStart=/usr/bin/docker daemon -H fd://.

这很奇怪,因为与 /etc/init.d/docker 上的配置不同,我认为这是服务配置。
奇怪的是, init.d 上的文件确实包含对 daemon 参数的任何引用 -H fd://

What it was strange because is different with configurations on /etc/init.d/docker which I thought that were the service configurations. The strange part it was that the file on init.d does contain any reference to daemon argument neither -H fd://.

经过一些研究和对系统目录的大量搜索,我发现删除这些目录(在有关此问题的讨论中得到帮助 docker github问题#22339 )。

After some research and a lot of searches of the system directories, I find out these directory (with help on the discussion on this issue docker github issue #22339).

从<$编辑了 ExecStart c $ c> /lib/systemd/system/docker.service ,并具有以下新值:
/ usr / bin / docker守护程序

Edited the ExecStart from /lib/systemd/system/docker.service with this new value: /usr/bin/docker daemon

并使用

{
  "hosts": [
    "fd://",
    "tcp://127.0.0.1:2376"
  ]
}

最后用重新启动服务service docker start ,现在我得到 service docker status 的绿灯。

Finally restarted the service with service docker start and now I get the "green light" on service docker status.

测试使用以下命令编辑新配置:

Tested the new configurations with:

$ docker run hello-world

Hello from Docker!
(...)

然后,

$ curl http://127.0.0.1:2376/v1.23/info
[JSON]

我希望这可以帮助遇到与我类似的问题的人! :)

I hope that this will help someone with a similar problem as mine! :)

这篇关于Docker-使用SystemD和“ daemon.json”启用远程HTTP API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆