在Docker中运行Jenkins-立即退出 [英] Running Jenkins in Docker - Exits immediately
问题描述
我正在尝试使用docker运行Jenkins服务器。
I'm trying to run a Jenkins server with docker.
我已经构建了映像,并尝试使用以下命令运行它:
I've built the image, and trying to run it with this command:
docker run -p 8080:8080 62a4e44bf4bf
62a4e44bf4bf是docker图像ID
The 62a4e44bf4bf is the docker image ID
每当我运行此命令时,它都会立即关闭。
Whenever I run this command, it shuts down immediately.
我尝试过以下命令:
docker run -i -t -p 8080:8080 62a4e44bf4bf
这将保持图像运行,但是我似乎无法使用以下ip从浏览器访问jenkins:localhost:8080
Which will keep the image running, but I can't seem to access the jenkins from my browser with this ip: localhost:8080
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
推荐答案
您的权限可能是当jenkins容器无法保持运行时,jenkins目录是一个问题。我做了 docker pull jenkins,但惊讶地发现它无法运行。 https://hub.docker.com/_/jenkins/
It is possible permissions on your jenkins directory are a problem when jenkins container will not stay running. I did 'docker pull jenkins' and was surprised to find it would not run. https://hub.docker.com/_/jenkins/
要调试错误,请使用-i(交互式标志)启动映像。 (如果您不知道自己的ID,请使用'docker ps -a | grep jenkins')
To debug your error then start the image using the -i (interactive flag). (use 'docker ps -a |grep jenkins' if you don't know your ID)
docker start 62a4e44bf4bf -i
我看到了这样的错误:
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?
所以我检查了/ var / jenkins_home的所有权和权限。
我看到$ PWD / jenkins目录是使用root:root 700权限创建的。我进行了调整(Sledgehammer方法): sudo chmod 777 $ PWD / jenkins。问题解决了。容器运行正常,并将jenkins的安装运行到该目录中。
So I checked /var/jenkins_home ownership and permissions. I saw that the $PWD/jenkins dir had been created with root:root 700 permission. I adjusted (Sledgehammer approach): 'sudo chmod 777 $PWD/jenkins'. Problem solved. Container ran ok and ran the install of jenkins into that directory.
我正在像这样运行jenkins容器:(PWD = / home / myuser,因此容器中的/ var / jenkins_home实际上是docker服务器上的$ PWD / jenkins)
I am running jenkins container like this: (PWD=/home/myuser so /var/jenkins_home in container is actually $PWD/jenkins on docker server)
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins
这篇关于在Docker中运行Jenkins-立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!