' docker cp' Jenkins docker容器中的命令将文件复制到目录中

时间:2017-02-24 09:45:21

标签: tomcat jenkins docker

我在docker容器中运行Jenkins服务器。

我通过以下命令启动了Jenkins容器:

  

sudo docker run --name jenkins -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -v / usr / bin / docker:/ usr / bin / docker - d weizhou / jenkins

在Jenkins的工作中,我想将构建的.war复制到本地机器(即从docker容器中)并启动另一个Tomcat docker服务器。但是,在使用命令docker cp之后,docker文件中的文件变为目录,也就是说,rpm.war文件变为rpm.war目录,并且没有任何内容。我应该如何解决这个问题,非常感谢。

以下是jenkins工作中Execute shell的帖子。

sudo docker exec tomcat  /usr/local/tomcat/bin/catalina.sh stop
sudo docker rm -f tomcat
sudo rm /home/rpm.war
sudo docker cp jenkins:/var/jenkins_home/workspace/rpm/target/rpm.war /home/
sudo chmod 777 /home/rpm.war
sudo docker run --name tomcat --link mysql:mysql  -p 80:8080 -v /home/rpm.war:/usr/local/tomcat/webapps/rpm.war --rm -d tomcat:7.0.75-jre7

以下是Jenkins控制台:

[rpm] $ /bin/sh -xe /tmp/hudson1380760968175739587.sh
+ sudo docker exec tomcat /usr/local/tomcat/bin/catalina.sh stop
+ sudo docker rm -f tomcat
tomcat
+ sudo rm /home/rpm.war
+ sudo docker cp jenkins:/var/jenkins_home/workspace/rpm/target/rpm.war /home/
+ sudo chmod 777 /home/rpm.war
+ sudo docker run --name tomcat --link mysql:mysql -p 80:8080 -v /home/rpm.war:/usr/local/tomcat/webapps/rpm.war --rm -d tomcat:7.0.75-jre7
205b8551375c1e3667965288d8d3d4240f8be765ea124e1ff57956e801509318
Finished: SUCCESS

rpm.war是目录,其中没有任何内容!

ubuntu@ip-172-31-66-12:/home$ ls -l
total 12
-rwxrwxrwx 1 root   root    368 Feb 24 09:23 rpmBuild.sh
drwxr-xr-x 2 root   root   4096 Feb 24 09:38 rpm.war
drwxr-xr-x 6 ubuntu ubuntu 4096 Feb 24 09:25 ubuntu

此外,脚本可以在本地机器上运行,并命令`docker cp'真正将文件复制为文件,而不是目录。

此外,我使用在真正的Jenkins而不是容器中运行的类似脚本,它确实有效并且文件被复制为文件。类似的脚本是

sudo docker exec tomcat  /usr/local/tomcat/bin/catalina.sh stop
sudo docker rm -f tomcat
sudo rm /home/rpm.war
sudo cp /var/lib/jenkins/workspace/rpm/target/rpm.war /home/
sudo chmod 777 /home/rpm.war
sudo docker run --name tomcat --link mysql:mysql  -p 80:8080 -v /home/rpm.war:/usr/local/tomcat/webapps/rpm.war --rm -d tomcat:7.0.75-jre7

最后,我的jenkins Dockerfile:

FROM jenkins

USER root
RUN apt-get update \
  && apt-get install -y sudo maven\
  && rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers

USER jenkins
RUN /usr/local/bin/install-plugins.sh bouncycastle-api:2.16.0 cloudbees-folder:5.17 structs:1.6 junit:1.20 antisamy-markup-formatter:1.5 pam-auth:1.3 windows-slaves:1.2 display-url-api:1.1.1 mailer:1.19 ldap:1.14 icon-shim:2.0.3 matrix-auth:1.4 token-macro:2.0 script-security:1.26 matrix-project:1.8 external-monitor-job:1.7 build-timeout:1.18 credentials:2.1.11 plain-credentials:1.4 workflow-step-api:2.9 credentials-binding:1.10 timestamper:1.8.8 resource-disposer:0.6 scm-api:2.0.7 workflow-api:2.11 workflow-basic-steps:2.4 ws-cleanup:0.32 ant:1.4 gradle:1.26 workflow-scm-step:2.3 ssh-credentials:1.13 git-client:2.2.1 jquery-detached:1.2.1 workflow-support:2.13 ace-editor:1.1 workflow-cps:2.27 git-server:1.7 workflow-cps-global-lib:2.6 pipeline-milestone-step:1.3 pipeline-build-step:2.4 pipeline-stage-step:2.2 pipeline-input-step:2.5 workflow-job:2.10 pipeline-graph-analysis:1.3 pipeline-rest-api:2.5 handlebars:1.1.1 momentjs:1.1.1 pipeline-stage-view:2.5 durable-task:1.13 workflow-durable-task-step:2.9 pipeline-model-api:1.0.2 pipeline-stage-tags-metadata:1.0.2 authentication-tokens:1.3 docker-commons:1.6 docker-workflow:1.10 pipeline-model-declarative-agent:1.0.2 branch-api:2.0.6 workflow-multibranch:2.12 pipeline-model-definition:1.0.2 workflow-aggregator:2.5 github-api:1.84 git:3.0.5 github:1.26.0 github-branch-source:2.0.3 pipeline-github-lib:1.0 github-organization-folder:1.6 mapdb-api:1.0.9.0 subversion:2.7.1 ssh-slaves:1.13 email-ext:2.57 build-token-root:1.4

0 个答案:

没有答案