iamarunk
iamarunk

Reputation: 145

Unable to start jenkins auctomatically inside docker container

I wrote a dockerfile to install jenkins inside container using chef.

I sucessfully installed but jenkins is not starting automatically. I implemented CMD command in dockerfile but couldn't do it.

I followed few article posted on this but didn't work in my case

dockerfile:

FROM centos:6

RUN yum -y update
RUN yum -y install wget
RUN yum -y install httpd
RUN wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-  ci.org/redhat/jenkins.repo
RUN rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
RUN yum -y install java
RUN yum -y install jenkins

CMD service jenkins start && tail -F /var/log/jenkins/jenkins.log

chef recipe:

include_recipe 'docker'

docker_node_data = '/tmp/docker1'

directory docker_node_data do
  action :create
end

cookbook_file "#{docker_node_data}/Dockerfile" do
  source 'Dockerfile'
end

docker_image 'jenkins7' do
  tag 'latest'
  source docker_node_data
  action :build
end

docker_container 'jenkins7' do
  detach true
  command 'top -b -d 5'
  port '8080:8080'
  action :run
end

Upvotes: 2

Views: 1036

Answers (1)

coderanger
coderanger

Reputation: 54211

This isn't really how Docker works. You wouldn't run a service inside the container, you would run a process. The container itself is a service. In this case you're using Chef as your service manager, which is probably a bad idea. Unfortunately Docker is not well-suited this this kind of management. The Right™ solution is probably veering off in to unhelpful answer territory (specifically you probably want something more like Chef setting up a systemd/Upstart/Supervisord/Runit service job using rkt to containerize jenkins).

To answer the more immediate question: your base image is CentOS 6 which uses Upstart. Upstart is not capable of running inside Docker because it wants to be the true PID 1 and have raw-level access to pretty much everything. If you change your entrypoint command to be something more like java -jar /path/to/jenkins.war or similar you should see it start. If you also want to the log export you might need something fancier though. Generally with a containerized app you would configure it to log directly to stdout rather than trying to tail a file like that.

Upvotes: 5

Related Questions