我试图在我的容器启动时运行 3 个服务(snmpd、sshd 和 centengine)
由于容器中的运行级别未知,因此服务不会启动。
我用这个 Dockerfile 构建了一个镜像:
FROM centos:6.7
MAINTAINER nael <me@mail>
# Update CentOS
RUN yum -y update
# Install wget
RUN yum install -y wget
# Get Centreon Repo
RUN wget http://yum.centreon.com/standard/3.0/stable/ces-standard.repo -O /etc/yum.repos.d/ces-standard.repo
# Install Packages (SSH, sudo, Centreon Poller & Engine, SNMP)
RUN yum install -y --nogpgcheck openssh-clients openssh-server centreon-poller-centreon-engine sudo net-snmp net-snmp-utils
# Install supervisord
RUN rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN yum --enablerepo=epel install -y supervisor
RUN mv -f /etc/supervisord.conf /etc/supervisord.conf.org
ADD supervisord.conf /etc/
# For sshd & centengine
EXPOSE 22 5669
# Change user password
RUN echo -e "password" | (passwd --stdin user)
# Disable PAM (causing issues while ssh login)
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
# Start supervisord
CMD ["/usr/bin/supervisord"]
这里是supervisord.conf文件
[supervisord]
nodaemon=true
pidfile=/var/run/supervisord.pid
logfile=/var/log/supervisor/supervisord.log
[program:centengine]
command=service centengine start
[program:snmpd]
command=service snmpd start
[program:sshd]
command=service sshd start
但是有了这个 Dockerfile 和 supervisord.conf,当我启动我的容器时,这些服务没有运行。
可能是什么问题?
最佳答案
不再使用 supervisord。
我只是在 Dockerfile 中包含一个包含所有 services ... start
命令的脚本。当我使用 docker run ...
创建我的容器时,我只是指定我想用我的脚本启动它。
& 效果很好。
感谢@warmoverflow 尝试解决这个问题。
关于service - 在容器启动时启动服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37190958/