我试图在 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
,我会尝试以下操作:
我可以成功运行
service supervisor restart
并获得Restarting supervisor:
输出。但是当我尝试使用 运行任何函数时
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
包括这个之后
- 我不再有任何一个
long.err.log
或long.out.log
填充在/var/log/
所有。 - 我可以运行
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
并在日志文件中观察它的输出。