代码之家  ›  专栏  ›  技术社区  ›  Arshanvit

在docker的jenkins中没有执行脚本

  •  0
  • Arshanvit  · 技术社区  · 6 年前

    COPY plugins.sh /usr/local/bin/plugins.sh
    # Adding required plugins
    COPY plugins.txt /plugins.txt
    RUN cd /usr/local/bin && ls -al && echo 'Hello'
    RUN /usr/local/bin/plugins.sh /plugins.txt
    

    其输出为:

    Step 64/73 : RUN cd /usr/local/bin && ls -al && echo 'Hello'
     ---> Running in 99b837dbd42c
    total 53068
    drwxr-xr-x 1 root root     4096 Jun 14 12:06 .
    drwxr-xr-x 1 root root     4096 Jan  9 19:37 ..
    -rwxr-xr-x 1 root root       87 Jun  6 01:55 docker-java-home
    -rw-rw-r-- 1 root root     5000 Jun 11 07:00 jenkins-support
    -rw-rw-r-- 1 root root     1301 Jun 11 07:00 jenkins.sh
    -rwxrwxrwx 1 root root 54308597 Jun  6 10:56 kubectl
    -rw-rw-r-- 1 root root     3917 Jun 11 07:00 plugins.sh
    Hello
    Removing intermediate container 99b837dbd42c
     ---> bfa6a11b18da
    Step 65/73 : RUN /usr/local/bin/plugins.sh /plugins.txt
     ---> Running in fd2f5cf8de36
    /bin/sh: /usr/local/bin/plugins.sh: Permission denied
    

    COPY plugins.sh /usr/local/bin/plugins.sh
    RUN chmod +x /usr/local/bin/plugins.sh 
    # Adding required plugins
    COPY plugins.txt /plugins.txt
    RUN cd /usr/local/bin && ls -al && echo 'Hello'
    RUN /usr/local/bin/plugins.sh /plugins.txt
    

    这又给了我一个错误:

    Step 63/74 : RUN chmod +x /usr/local/bin/plugins.sh
     ---> Running in 375d0c56e9c3
    chmod: changing permissions of '/usr/local/bin/plugins.sh': Operation not permitted
    The command '/bin/sh -c chmod +x /usr/local/bin/plugins.sh' returned a non-zero code: 1
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Arshanvit    6 年前

    这是个小错误,但它给了我们一个重要的教训:

    执行Dockerfile时,对于我们从本地复制到docker容器的所有文件,权限将始终保持原样,并且不能更改。

    主机上的权限:

    -rw-rw-r--  1 sevenos sevenos 1301 Jun 11 12:30 jenkins.sh
    -rw-rw-r--  1 sevenos sevenos 3917 Jun 11 12:30 plugins.sh
    -rw-rw-r--  1 sevenos sevenos  806 Jun 11 12:30 plugins.txt
    

    Docker中的权限:

    Step 64/73 : RUN cd /usr/local/bin && ls -al && echo 'Hi'
     ---> Running in 71c1dff30ffc
    total 53068
    drwxr-xr-x 1 root root     4096 Jun 14 12:06 .
    drwxr-xr-x 1 root root     4096 Jan  9 19:37 ..
    -rwxr-xr-x 1 root root       87 Jun  6 01:55 docker-java-home
    -rw-rw-r-- 1 root root     5000 Jun 11 07:00 jenkins-support
    -rw-rw-r-- 1 root root     1301 Jun 11 07:00 jenkins.sh
    -rwxrwxrwx 1 root root 54308597 Jun  6 10:56 kubectl
    -rw-rw-r-- 1 root root     3917 Jun 11 07:00 plugins.sh