Launch Jenkins in Docker - Exit Immediately

I am trying to start Jenkins server with docker.

I created an image and tried to run it with this command:

docker run -p 8080:8080 62a4e44bf4bf

      

62a4e44bf4bf is the docker image id

Whenever I run this command, it turns off immediately.

I tried this command:

docker run -i -t -p 8080:8080 62a4e44bf4bf

      

Which will support the image, but I cannot access jenkins from my browser using this ip: localhost: 8080

DOCKERFILE:

FROM ubuntu:latest

#Oracle Java7 install
RUN apt-get install software-properties-common -y
RUN apt-get update
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java7-installer

#Jenkins install
RUN wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
RUN sudo echo "deb http://pkg.jenkins-ci.org/debian binary/" >>     /etc/apt/sources.list
RUN apt-get update
RUN apt-get install --force-yes -y jenkins

#Zip support install
RUN apt-get update
RUN apt-get -y install zip

#Unzip hang.zip
#RUN cp /shared/hang.zip /var/lib/jenkins
#RUN unzip -o /var/jenkins/hang.zip -d /var/lib/jenkins/

#Restart jenkins server
RUN service jenkins start

EXPOSE 8080

      

+3


source to share


2 answers


@Detilium There is Dockerfile

no CMD or ENTRYPOINT in yours, so it automatically exits because there is nothing to run in your container. According to your own answer, you probably did it with exec

or by starting bash and starting it manually, I suppose?

There's something wrong with you Dockerfile

. The Docker container must start the process as pid 1

(inside the container) and it must run in the foreground (no daemon).

Also, images do not support file systems. if you start the process at the image creation stage (c Dockerfile

), the fact that it works will not be / saved /, so it will not be started again when you start the container based on that image. The default command run by docker when starting a container is defined with CMD

.

RUN service jenkins start

      



The line above doesn't work. It will start jenkins at this build step and create a layer (which might even be empty). But next layer to be created (different step or actual docker run

) will not work with jenkins service / process.

For / inspiration / for Jenkins, Dockerfile

you can look at https://github.com/aespinosa/docker-jenkins/blob/master/Dockerfile . Please note that ENTRYPOINT ["java", "-jar", "/opt/jenkins.war"]

it may also be CMD ["java", "-jar", "/opt/jenkins.war"]

.

I recommend that you read the following documentation for a deeper understanding of docker: https://docs.docker.com/userguide/dockerimages/ , https://docs.docker.com/reference/builder/ and https: //docs.docker. com / articles / dockerfile_best-practices / .

+1


source


Maybe the permissions to your jenkins directory are an issue where the jenkins container won't work. I did docker, and was surprised to see that it didn't work. https://hub.docker.com/_/jenkins/

To debug your error, run the image using the -i (interactive flag). (use "docker ps -a | grep jenkins" if you don't know your id)

docker start 62a4e44bf4bf -i

      

I've seen an error like this:



touch: cannot touch ‘/var/jenkins_home/copy_reference_file.log’: Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

      

So I checked the ownership and permissions of / var / jenkins_home. I saw that the $ PWD / jenkins directory was created as root: root 700. I configured (Sledgehammer approach): "sudo chmod 777 $ PWD / jenkins". The problem has been solved. The container worked fine and started installing jenkins to that directory.

I start jenkins container like this: (PWD = / home / myuser so / var / jenkins_home in container actually $ PWD / jenkins in docker server)

docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins

      

+1


source







All Articles