4

我试图在 docker 上下文中重新创建本教程中的步骤,ubuntu 映像安装在 OS X 上的 virtualbox 中运行的 coreos 下。

我已经设置了一个 Dockerfile,它具有以下步骤:

# Install docker basics
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y

# Install supervisor
RUN apt-get install -y supervisor
RUN mkdir -p /var/run/sshd
RUN mkdir -p /var/log/supervisor
RUN mkdir -p /etc/supervisor/conf.d

# tutorial suite
ADD ./etc/long.sh /usr/local/bin/long.sh
RUN /bin/chmod 0777 /usr/local/bin/long.sh
ADD ./etc/long_script.conf /etc/supervisor/conf.d/long_script.conf

# create supervisord user
RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot

# start supervisord
RUN sudo service supervisor start

它将以下文件从相对/etc/目录中复制出来:

long.sh

#!/bin/bash
while true
do
    # Echo current date to stdout
    echo `date`
    # Echo 'error!' to stderr
    echo 'error!' >&2
    sleep 1
done

long_script.conf

[program:long_script]
command=/usr/local/bin/long.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/long.err.log
stdout_logfile=/var/log/long.out.log

/var/log/long.out.log它正确加载了所有内容,但是在或中都没有相应的输出/var/log/long.err.log,尽管两个文件都存在于该目录中。

当我使用 / 加载图像时/bin/bash,我会尝试以下操作:

  1. 我可以成功运行service supervisor restart并获得Restarting supervisor:输出。

  2. 但是当我尝试使用 运行任何函数时supervisorctl,我得到错误,即unix:///var/run/supervisor.sock refused connection

我检查了输出,/var/log/supervisor/supervisord.log它给了我:

2014-03-17 08:54:48,090 CRIT Supervisor running as root (no user in config file)
2014-03-17 08:54:48,090 WARN Included extra file "/etc/supervisor/conf.d/long_script.conf" during parsing
2014-03-17 08:54:48,161 INFO RPC interface 'supervisor' initialized
2014-03-17 08:54:48,161 WARN cElementTree not installed, using slower XML parser for XML-RPC
2014-03-17 08:54:48,161 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-03-17 08:54:48,163 INFO daemonizing the supervisord process
2014-03-17 08:54:48,164 INFO supervisord started with pid 10
2014-03-17 08:54:49,165 INFO spawned: 'long_script' with pid 13
[error] client.go:2296 Error resize: Error: resize: bad file descriptor

谷歌搜索建议我包含一个准系统supervisord.conf文件,该文件明确地将应用程序指向该supervisord.sock文件,因此我在 Dockerfile 中添加了以下内容:

# Add supervisor config file
ADD ./etc/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

然后添加一个supervisord.conf看起来像这样的文件:

[supervisord]
logfile=/var/log/supervisor/supervisord.log
loglevel=error
nodaemon=false

[supervisorctl]
serverurl = unix:///var/run/supervisord.sock

包括这个之后

  1. 我不再有任何一个long.err.loglong.out.log填充在/var/log/所有。
  2. 我可以运行service supervisor restart,但现在当我运行时supervisorctl,我得到的错误变为unix:///var/run/supervisord.sock no such file.

我检查了输出,/var/log/supervisor/supervisord.log它给了我:

2014-03-17 08:48:29,715 CRIT Supervisor running as root (no user in config file)[error] client.go:2296 Error resize: Error: resize: bad file descriptor

认为这可能是用户权限问题,我尝试将supervisord.conf文件切换到

[supervisord]
logfile=/var/log/supervisor/supervisord.log
loglevel=error
nodaemon=false
user=nonroot

[supervisorctl]
serverurl = unix:///var/run/supervisord.sock

将以下内容添加到我的之后Dockerfile

RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot

但这让我在编译时出现以下错误

Step XX : RUN service supervisor start
 ---> Running in fdcb12ff3cfa
Traceback (most recent call last):
  File "/usr/bin/supervisord", line 9, in <module>
load_entry_point('supervisor==3.0a8', 'console_scripts', 'supervisord')()
  File "/usr/lib/pymodules/python2.7/supervisor/supervisord.py", line 371, in main
go(options)
  File "/usr/lib/pymodules/python2.7/supervisor/supervisord.py", line 381, in go
d.main()
  File "/usr/lib/pymodules/python2.7/supervisor/supervisord.py", line 88, in main
info_messages)
  File "/usr/lib/pymodules/python2.7/supervisor/options.py", line 1231, in make_logger
stdout = self.nodaemon,
  File "/usr/lib/pymodules/python2.7/supervisor/loggers.py", line 325, in getLogger
handlers.append(RotatingFileHandler(filename,'a',maxbytes,backups))
  File "/usr/lib/pymodules/python2.7/supervisor/loggers.py", line 180, in __init__
FileHandler.__init__(self, filename, mode)
  File "/usr/lib/pymodules/python2.7/supervisor/loggers.py", line 106, in __init__
self.stream = open(filename, mode)

登录/bin/bash/并立即执行cat/var/log/supervisor/supervisord.log产生:

2014/03/17 08:57:36 build: The command [/bin/sh -c service supervisor start] returned a non-zero code: 1
2014-03-17 08:54:48,090 CRIT Supervisor running as root (no user in config file)
2014-03-17 08:54:48,090 WARN Included extra file "/etc/supervisor/conf.d/long_script.conf" during parsing
2014-03-17 08:54:48,161 INFO RPC interface 'supervisor' initialized
2014-03-17 08:54:48,161 WARN cElementTree not installed, using slower XML parser for XML-RPC
2014-03-17 08:54:48,161 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-03-17 08:54:48,163 INFO daemonizing the supervisord process
2014-03-17 08:54:48,164 INFO supervisord started with pid 10
2014-03-17 08:54:49,165 INFO spawned: 'long_script' with pid 13
[error] client.go:2296 Error resize: Error: resize: bad file descriptor

这里有什么问题?我只是希望能够通过运行这个 shell 脚本supervisord并在日志文件中观察它的输出。

4

3 回答 3

3

您也正在启动服务 - 但不会让它运行。

RUN sudo service supervisor start

您可能应该直接运行它:

CMD ["/usr/bin/supervisord"]

您可能还必须/需要向该 CMD 添加一些参数。请参阅:Docker/Supervisord 示例

于 2014-03-17T20:17:42.903 回答
3

我也有这个问题,sudo没有帮助。因此,我没有使用 unix 套接字,而是使用了 tcp 套接字:

[inet_http_server]
port=:9001
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=http://localhost:9001

您还可以仅绑定到 localhost ( 127.0.0.1:9001) 并添加可选的用户和密码。

于 2015-05-28T05:46:36.227 回答
1

我知道这是一个过时的问题。但是,由于您尚未接受答案,因此我正在发布。使用 docker 和 supervisor 时,确保在前台运行 supervisord。您可以通过更改您的 supervisord.conf 来做到这一点。放

nodaemon=true
于 2015-09-02T16:05:53.617 回答