运行bash脚本的docker入口点将获得“权限被拒绝"信息, [英] docker entrypoint running bash script gets "permission denied"

查看:101
本文介绍了运行bash脚本的docker入口点将获得“权限被拒绝"信息,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对我的node.js应用进行docker化.构建容器后,我希望它运行git clone,然后启动节点服务器.因此,我将这些操作放在.sh脚本中.并在ENTRYPOINT中将脚本作为单个命令运行:

I'm trying to dockerize my node.js app. When the container is built I want it to run a git clone and then start the node server. Therefore I put these operations in a .sh script. And run the script as a single command in the ENTRYPOINT:

FROM ubuntu:14.04

RUN apt-get update && apt-get install -y build-essential libssl-dev gcc curl npm git

#install gcc 4.9
RUN apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
RUN apt-get update
RUN apt-get install -y libstdc++-4.9-dev

#install newst nodejs
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN apt-get install -y nodejs

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ADD package.json /usr/src/app/
RUN npm install

ADD docker-entrypoint.sh /usr/src/app/

EXPOSE 8080

ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"] 

我的docker-entrypoint.sh看起来像这样:

My docker-entrypoint.sh looks like this:

git clone git@<repo>.git
git add remote upstream git@<upstream_repo>.git

/usr/bin/node server.js

构建此图像并运行后:

docker run --env NODE_ENV=development -p 8080:8080 -t -i <image>

我得到:

docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.

我将其装入容器,并且docker-entrypoint.sh的许可为:

I shell into the container and the permission of docker-entrypoint.sh is:

-rw-r--r-- 1 root root 292 Aug 10 18:41 docker-entrypoint.sh

三个问题:

  1. 我的bash脚本语法错误吗?

  1. Does my bash script have wrong syntax?

在将bash文件添加到图像之前如何更改其权限?

How do I change the permission of a bash file before adding it into an image?

在不使用bash脚本的情况下在入口点运行多个git命令的最佳方法是什么?

What's the best way to run multiple git commands in entrypoint without using a bash script?

谢谢.

推荐答案

  1. 权限被拒绝"可阻止您的脚本被完全调用 .因此,唯一可能与之相关的语法是第一行("shebang")的语法,根据目标文件系统的布局,其外观应类似于#!/usr/bin/env bash#!/bin/bash或类似.

  1. "Permission denied" prevents your script from being invoked at all. Thus, the only syntax that could be possibly pertinent is that of the first line (the "shebang"), which should look like #!/usr/bin/env bash, or #!/bin/bash, or similar depending on your target's filesystem layout.

很可能未将文件系统权限设置为允许执行. shebang可能还会引用一些不可执行的内容,但这可能性.

Most likely the filesystem permissions not being set to allow execute. It's also possible that the shebang references something that isn't executable, but this is far less likely.

解决以前的问题很容易.

Mooted by the ease of repairing the prior issues.


简单阅读


The simple reading of

docker: Error response from daemon: oci runtime error: exec: "/usr/src/app/docker-entrypoint.sh": permission denied.

...是该脚本未标记为可执行文件.

...is that the script isn't marked executable.

RUN ["chmod", "+x", "/usr/src/app/docker-entrypoint.sh"]

将在容器中解决此问题.或者,您可以确保Dockerfile引用的本地副本是可执行文件,然后使用COPY(明确记录为保留元数据).

will address this within the container. Alternately, you can ensure that the local copy referenced by the Dockerfile is executable, and then use COPY (which is explicitly documented to retain metadata).

这篇关于运行bash脚本的docker入口点将获得“权限被拒绝"信息,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆