问题:容器启动时启动服务

我试图在我的容器启动时运行 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 试图解决这个问题。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐