Docker中的Logstash - 通过卷挂载时找不到配置文件 [英] Logstash in Docker - config file not found when mounted though a volume

查看:4647
本文介绍了Docker中的Logstash - 通过卷挂载时找不到配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:似乎是一个boot2docker的东西...在ubuntu vm运行的docker中工作正常。

It seems to be a boot2docker thing... works fine in an ubuntu vm running docker.

我正在尝试在Docker容器中启动logstash,但是当我将配置文件作为一个卷进行安装时,似乎没有找到它。有趣的是,如果我使用bash启动容器,我可以看到配置文件,并运行与docker相同的命令,它可以工作。

I'm trying to fire up logstash in a Docker container but when I mount the config file as a volume, it doesn't seem to find it. Interestingly, if I start up the container with bash, I can see the config file in there and running the same command as what docker would, it works.

Docker文件

FROM ubuntu:14.04
MAINTAINER cvallance

RUN apt-get update
RUN apt-get -yqq install openjdk-7-jre
RUN apt-get -yqq install curl
RUN mkdir /opt/logstash \
  && cd /opt/logstash \
  && curl -O https://download.elastic.co/logstash/logstash/logstash-1.4.2.tar.gz \
  && tar zxvf logstash-1.4.2.tar.gz

CMD ["/opt/logstash/logstash-1.4.2/bin/logstash", "agent", "--verbose", "-f", "/etc/logstash/sample.conf"]

位于 $(pwd)/config/sample.conf

Config file located at $(pwd)/config/sample.conf

input {
  stdin { }
}

output {
  stdout {
    codec => rubydebug
  }
}

Docker构建命令:

docker build -t cvallance/logstash .

Docker运行命令:

docker run -ti -v $(pwd)/config:/etc/logstash cvallance/logstash

错误:

Error: No config files found:  /etc/logstash/sample.conf
Can you make sure this path is a logstash config file?

但是,如果我从bash会话在容器内运行相同的命令喜欢这样...

BUT if I run the same command inside the container from a bash session like so...

docker run -ti -v $(pwd)/config:/etc/logstash cvallance/logstash bash
...
root@d3fd885903dd:/# /opt/logstash/logstash-1.4.2/bin/logstash agent --verbose -f /etc/logstash/sample.conf

一切都按预期工作。即输入和输出

Everything works as expected. I.e. input and output

testing
{
       "message" => "testing",
      "@version" => "1",
    "@timestamp" => "2015-04-10T00:06:33.878Z",
          "host" => "d3fd885903dd"
}


推荐答案

一个boot2docker的事情,请记住,这是为您提供基于Tiny核心的Linux主机, 没有任何持久性 / var / lib / docker 除外)

If it is a "boot2docker" thing, remember that is offers you a Linux host based on Tiny core, without any persistence (except /var/lib/docker).

我所做的是确保 Oracle_VM_VirtualBox_Extension_Pack ,并获取我的 / c / Users /< yourLogin> 在我的boot2docker ssh会话中自动共享。

无论我需要保留什么都写在那里( / c / Users /< yourLogin> / ... ),而不是其他任何地方。

如果您必须将主机目录作为数据卷挂载,则应从 / c / Users / < yourLogin> / ...

What I do is make sure the Oracle_VM_VirtualBox_Extension_Pack is installed, and get my /c/Users/<yourLogin> automatically shared in my boot2docker ssh session.
Whatever I need to keep is written there (/c/Users/<yourLogin>/...), not anywhere else.
If you have to mount a host directory as a data volume, you should mount a folder from /c/Users/<yourLogin>/....

另一个选项(它仍然存在)是定义一个数据卷容器,它将在 /var/lib/docker/volumes/conf.json 和(对于实际文件)在 / var / lib / docker / vfs / xxx 中。

这是首选最佳实践,因为它不会将您的数据容器链接到特定的主机平台(这里' / c / Users /< yourLogin> 实际上取决于 VM 主机,在Windows上!不是很便携。)

The other option (which does persists) is to define a Data Volume Container, which will persists data in /var/lib/docker/volumes/conf.json, and (for the actual files) in /var/lib/docker/vfs/xxx.
That is the preferred best-practice as it doesn't link your data container to a specific host platform (here '/c/Users/<yourLogin> actually depends on the VM host, on Windows! Not very portable.)

这篇关于Docker中的Logstash - 通过卷挂载时找不到配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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