我正在运行以下命令:
docker run --name myjenkins -u root -d -p 8080:8080 -p 50000:50000 -v jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --privileged vaish
docker exec -it myjenkins vaish
service docker start
service docker status
输出为[FAIL] Docker未运行...失败!
注意:我已经通过dockerfile安装了docker 注意:我的应用程序是一组Docker容器
当我在主机上检查服务docker状态时,它处于活动状态(正在运行),但问题出在容器内部!
Dockerfile:
FROM jenkins/jenkins:lts
ENV JENKINS_SLAVE_AGENT_PORT '50000'
USER $USER
WORKDIR /var/jenkins_home/workspace/pipelineDemo@script
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
RUN apt-get update
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash -
RUN apt-get install -y nodejs
RUN apt-get update
RUN apt-get install -y npm
RUN npm install -g npm
RUN apt-get install python3
RUN apt-get install --reinstall make
RUN npm install --global gulp-cli
RUN npm install --global gulp
RUN apt-get -y install g++
RUN apt-get update
RUN apt-get install
RUN apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
RUN apt-get update
RUN apt-get install -y docker-ce
RUN curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
RUN chmod +x /usr/local/bin/docker-compose
RUN usermod -aG docker jenkins
USER jenkins
COPY Jenkinsfile /var/jenkins_home/workspace/pipelineDemo@script
CMD [ "npm", "start" ]
当我在jenkins docker容器中没有docker并且运行npm run install时,我会收到以下日志:为了避免这些错误,我不得不在我的jenkins docker容器中安装docker和docker compose
> /var/jenkins_home/workspace/pipelineDemo@script
> node tasks/down.js
✖ Command failed: docker-compose kill
/bin/sh: 1: docker-compose: not found
>/var/jenkins_home/workspace/pipelineDemo@script
> node tasks/build.js
✔ bundle admin
✔ bundle front-end
✖ build admin
→ /bin/sh: 1: docker: not found
✖ build bank-accounts
→ /bin/sh: 1: docker: not found
注意:在我的主机上,docker已安装了npm i,npm运行安装命令
答案 0 :(得分:0)
我有同样的问题。我找到了解决方法here:
启动Jenkins容器时,请使用-v
将主机的docker.sock移至该容器:
docker run -v /var/run/docker.sock:/var/run/docker.sock ...
在Jenkins由用户jenkins
运行时,您运行根目录也可能是一个问题。我希望会有一个不同的错误。
这是我的Jenkinsfile(我没有安装docker-compose
)
FROM jenkins/jenkins
USER root
RUN apt update && apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
RUN apt update && apt install -y docker-ce
RUN usermod -aG docker jenkins
USER jenkins
我用以下容器启动容器
docker run --name mycustomjenkins \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock <IMAGE-ID>
这样,我就可以在Jenkins中使用Docker代理了。
答案 1 :(得分:0)
我无法使myjenkins容器独立,因此我在docker run命令中使用--net = hots运行它,因此它至少可以正常工作。不是我想要的,但最终还是这样。