【问题标题】:Docker File: Chmod on Entrypoint ScriptDocker 文件:入口点脚本上的 Chmod
【发布时间】:2018-08-01 19:39:39
【问题描述】:

我有什么理由需要在我的入口点脚本上 chmod +x 吗? Redis 似乎没有在他们的 dockerfile (https://github.com/docker-library/redis/blob/109323988b7663bceaf4a01c3353f8934dfc002e/2.8/Dockerfile) 中为其入口点脚本执行此操作。

Dockerfile:

# Generic Docker Image for Running Node app from Git Repository
FROM    node:0.10.33-slim
ENV NODE_ENV production

# Add script to pull Node app from Git and run the app
COPY docker-node-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

EXPOSE  8080
CMD ["--help"]

【问题讨论】:

    标签: docker dockerfile


    【解决方案1】:

    redis 不需要这样做,因为他们的脚本已经有 exec 标志:

    ~/redis/2.8$ ls -l docker-entrypoint.sh 
    -rwxrwxr-x 1 igor igor 109 Dec  3 23:52 docker-entrypoint.sh
    

    如果您要为您的 docker-node-entrypoint.sh 脚本执行此操作,您也不需要 Dockerfile 中的 chmod。

    这是可能的,因为 git core.fileMode 选项默认为 true,因此文件的可执行位被尊重。

    【讨论】:

      【解决方案2】:

      Docker 会将文件复制到具有源权限的容器中。如果您在推送到代码仓库或构建主机的链中某处剥离 Linux 可执行位,那么您需要重新添加这些执行权限。我见过 Windows 用户最常报告的这个问题,他们将代码下载到不支持 Linux 权限位的文件系统。希望我们能收到COPY --chmod solution soon that will eliminate the need for an extra layer

      【讨论】:

      • COPY --chmod 现在可以使用(从 Docker v20.10 开始)。见here。请注意,截至目前,此更改在官方文档中为not yet reflected
      猜你喜欢
      • 1970-01-01
      • 2016-10-08
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-04-28
      相关资源
      最近更新 更多