Puppet container wont start automatically

时间:2016-07-11 20:36:28

标签: docker puppet

So I have created a puppet container for a certificate authority. It works, but does not start correctly. Here is my Dockerfile:

FROM centos:6
RUN yum update -y
RUN rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
RUN yum install -y ruby puppet-server  
ADD puppet.conf /etc/puppet/puppet.conf

VOLUME ["/var/lib/puppet/ssl/"]
EXPOSE 9140

#NOTHING BELOW THIS COMMENT RUNS
RUN puppet master --verbose 

CMD service puppetmaster start
CMD chkconfig puppetmaster on
CMD []

I can then start the container with the following run(note that I named the image ca-puppet):

docker run -d -p 9140:9140 -it --name ca-puppet \
-v /puppet-host/ssl:/var/lib/puppet/ssl \
ca-puppet bash

The issue is that I need to docker exec into the container and run the following commands to get it started and create the ca certificates in its ssl directory:

puppet master --verbose 
service puppetmaster start
chkconfig puppetmaster on

I have a feeling I should be using some other Docker file commands to run the last 3 commands. What should that be?

1 个答案:

答案 0 :(得分:1)

  

Dockerfile中只能有一条CMD指令。如果你列出   不止一个CMD,那么只有最后一个CMD才会生效。

  

如果用户指定了docker run的参数,那么它们将覆盖   CMD中指定的默认值。

但是,对于大多数主流发行版而言,在Docker中使用默认进程管理器(例如,SysV,systemd等)可能会导致问题(无需进行大量修改)。但是,您通常不需要它 - 特别是如果您只运行一个应用程序(通常被认为是最佳实践)。在Docker容器中,通常希望主应用程序成为第一个进程(PID 1)。

你可以通过不守护木偶并通过以下方式将其作为默认容器命令启动来实现:

CMD puppet master --verbose --no-daemonize

使用Docker主机管理它(通过restart政策等)。