不在docker中的jenkins中执行的脚本

时间:2018-06-14 12:24:02

标签: docker jenkins

我正在为jenkins设置docker并在其中安装插件。对于此执行,Dockerfile中有以下几行:

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 个答案:

答案 0 :(得分:0)

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

执行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