Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

./build.sh: Permission denied #238

Closed
nikki603 opened this issue Oct 8, 2016 · 21 comments · Fixed by #278
Closed

./build.sh: Permission denied #238

nikki603 opened this issue Oct 8, 2016 · 21 comments · Fixed by #278

Comments

@nikki603
Copy link

nikki603 commented Oct 8, 2016

Environment:

  • Windows 10
  • Docker version 1.12.1
  • docker-compose version 1.8.0 and Docker Hub

I had the missing gcc error and did the workaround of using gliderlabs/logspout:master and putting a copy of build.sh in my local directory. Now when I try to build, I get an error of ./build.sh: Permission denied. You can see full build log at https://hub.docker.com/r/nikki603/logspoutkinesis/builds/bchksm9an3agrmdxavr5o78/

I get the same error when running docker-compose locally.

docker-compose build logspout
Building logspout
Step 1 : FROM gliderlabs/logspout:master
# Executing 3 build triggers...
Step 1 : COPY ./build.sh /src/build.sh
Step 1 : COPY ./modules.go /src/modules.go
Step 1 : RUN cd /src && ./build.sh "$(cat VERSION)-custom"
 ---> Running in 48852ae2f7b1
/bin/sh: ./build.sh: Permission denied
ERROR: Service 'logspout' failed to build: The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126

build.sh file permission locally are -rwxr-xr-x

I believe this is related to bug docker/compose#3716

@christianbundy
Copy link

Yep, this will be resolved in Docker Compose 1.9.0. until then you'll need to add RUN chmod +x /src/build.sh to your Dockerfile.

@anisimovsergey
Copy link

anisimovsergey commented Nov 24, 2016

Can RUN chmod +x /src/build.sh really help? A docker build executes ONBUILD commands before any command in a child Dockerfile. Therefore, ONBUILD RUN cd /src && ./build.sh "$(cat VERSION)-custom" will be executed before RUN chmod +x /src/build.sh.

I've got the same issue but in my case I build my custom image in a build pipeline and when the build agent (GOCD) pulls the files to build a custom logspout, build.sh has the following attributes
-rw-r--r--. 1 go docker 417 Nov 11 11:12 build.sh and docker build fails with the same error.

I believe that RUN chmod +x /src/build.sh should be in logspout's Dockerfile.

@christianbundy
Copy link

@anisimovsergey What version of docker-compose are you using? This should be fixed in 1.9.0.

@anisimovsergey
Copy link

anisimovsergey commented Nov 26, 2016

I'm not using docker-compose at all, a simple docker build is failing if you develop on Windows and build on Linux roudtriping your code through a Git server (in my case it's even worse, it's Microsoft's TFS Git) because the file permissions are different. There is no way to specify +x permission on Windows 7. Moreover, I don't think it's guaranteed by git spec to preserve the file permissions at all, it just happens that GitHub supports it for the Linux-to-Linux workflow. Please correct me if I'm wrong.

@christianbundy
Copy link

@anisimovsergey Which version of Git are you using? The executable bit is synthesized, meaning that when you're using Windows to build an image, Docker will chmod +x on each of the files being added to the image. This was resolved in moby/moby#11148 for Docker, and docker/docker-py#1228 for docker-py (which runs docker-compose and friends).

@anisimovsergey
Copy link

anisimovsergey commented Nov 26, 2016

The Git version I'm using on Windows is "Git for Windows 2.8.1". I'm using windows git and building my Docker images on a Virtual Box VM with Ubuntu 14.04.5. All my files in a mapped folder from windows have permissions: -rwxrwxrwx and all the folders: drwxrwxrwx because Virtual Box doesn't know about the real permissions it falls back with enabling everything. Docker version I'm using for building in the VM is: 1.11.2 I can build my image successfully in this environment using logspout's original docker image, no problem at all.

However, on my build agent which is running on CentOS 7.2, I'm using Git client 1.8.3.1 and docker version 1.12.3.
When my build agent pulls the repository with build.sh it has -rw-r--r-- permissions and the subsequent build fails with:

17:53:38.032 Step 1 : COPY ./build.sh /src/build.sh
17:53:38.033 Step 1 : COPY ./modules.go /src/modules.go
17:53:38.033 Step 1 : RUN cd /src && ./build.sh "$(cat VERSION)-custom"
17:53:38.033  ---> Running in 0ac0f8ce2106
17:53:38.033 /bin/sh: ./build.sh: Permission denied

I have a workaround but I would rather prefer using the original logspout's Dockerfile.

@josegonzalez
Copy link
Member

Can you change that line to chmod +x and then the execution?

@anisimovsergey
Copy link

anisimovsergey commented Nov 26, 2016

No I can't, because those lines are from the logspout's Dockerfile

ONBUILD COPY ./build.sh /src/build.sh
ONBUILD COPY ./modules.go /src/modules.go
ONBUILD RUN cd /src && ./build.sh "$(cat VERSION)-custom"

Nether can I do RUN chmod +x /src/build.sh in my Dockerfile because ONBUILD commands are executed before the commands in the inherited Dockerfile (mine).

@josegonzalez
Copy link
Member

Would this fix it?

ONBUILD RUN cd /src && chmod +x build.sh && ./build.sh "$(cat VERSION)-custom"

@anisimovsergey
Copy link

anisimovsergey commented Nov 28, 2016

@josegonzalez Yes, indeed, the proposed change should fix the problem.

@stour
Copy link

stour commented Dec 1, 2016

I'm getting the same error and that prevents me from running my custom logspout image.
@josegonzalez: Any plan to apply the suggested fix in logspout's Dockerfile ?

@trondvh
Copy link
Contributor

trondvh commented Nov 26, 2017

This issue was reintroduced in ae888cc? @michaelshobbs

@josegonzalez
Copy link
Member

@trondvh can you file a new issue with the full output of the issue you are seeing?

@djeeg
Copy link

djeeg commented Nov 30, 2017

Same, am getting this issue again

As @trondvh says, the previous fix, "&& chmod +x build.sh", looks like it was removed from the Dockerfile as part of recent update

Is it not needed anymore?

@christianbundy
Copy link

@djeeg Can you post more info about your environment (e.g. your Docker version)?

@michaelshobbs
Copy link
Member

I checked the file in with the executable bit set and I just verified that a new clone of the repo shows that it's executable. Not sure why you're still seeing this issue. Feel free to open a PR to bring back the chmod cmd if needed.

@djeeg
Copy link

djeeg commented Nov 30, 2017

Note: this works when I build the image locally using [Windows host + hyper-V + docker-machine + boot2docker + docker 17.11.0]

It doesn't work if I build the image in the cloud using [Visual Studio Online + GIT repository]

Project structure is standard
directory: logspout

  • file: build.sh
  • file: Dockerfile
  • file: modules.go
  • file: VERSION

Dockerfile has
FROM gliderlabs/logspout:master

modules.go has
"github.com/looplab/logspout-logstash"

When triggering a build in VSTS, this happens (other images in VSTS are building okay)

2017-11-30T11:11:33.5307250Z ##[section]Starting: Build an image
2017-11-30T11:11:33.5602790Z ==============================================================================
2017-11-30T11:11:33.5618200Z Task : Docker
2017-11-30T11:11:33.5633410Z Description : Build, tag, push, or run Docker images, or run a Docker command. Task can be used with Docker or Azure Container registry.
2017-11-30T11:11:33.5647590Z Version : 0.3.2
2017-11-30T11:11:33.5661550Z Author : Microsoft Corporation
2017-11-30T11:11:33.5675660Z Help : More Information
2017-11-30T11:11:33.5690690Z ==============================================================================
2017-11-30T11:11:36.6498410Z Sending build context to Docker daemon 6.144kB
2017-11-30T11:11:36.6507080Z
2017-11-30T11:11:36.6969280Z Step 1/2 : FROM gliderlabs/logspout:master
2017-11-30T11:11:37.1598370Z master: Pulling from gliderlabs/logspout
2017-11-30T11:11:37.1627880Z b56ae66c2937: Pulling fs layer
2017-11-30T11:11:37.1744340Z 08ba3ad758a2: Pulling fs layer
2017-11-30T11:11:37.1761370Z 6ede64ba6796: Pulling fs layer
2017-11-30T11:11:37.3392110Z 08ba3ad758a2: Verifying Checksum
2017-11-30T11:11:37.3414840Z 08ba3ad758a2: Download complete
2017-11-30T11:11:37.3632530Z b56ae66c2937: Verifying Checksum
2017-11-30T11:11:37.3647590Z b56ae66c2937: Download complete
2017-11-30T11:11:37.4137140Z 6ede64ba6796: Verifying Checksum
2017-11-30T11:11:37.4153800Z 6ede64ba6796: Download complete
2017-11-30T11:11:37.6433240Z b56ae66c2937: Pull complete
2017-11-30T11:11:37.7559270Z 08ba3ad758a2: Pull complete
2017-11-30T11:11:38.1644620Z 6ede64ba6796: Pull complete
2017-11-30T11:11:38.1897650Z Digest: sha256:bdd052e42ff519202b8c4e4be11f4803803118dc4ecfa41970c573afecf90ac6
2017-11-30T11:11:38.2152390Z Status: Downloaded newer image for gliderlabs/logspout:master
2017-11-30T11:11:38.2179230Z �[91m# Executing 3 build triggers...
2017-11-30T11:11:38.2238690Z �[0mStep 1/1 : COPY ./build.sh /src/build.sh
2017-11-30T11:11:38.5869930Z Step 1/1 : COPY ./modules.go /src/modules.go
2017-11-30T11:11:38.9167170Z Step 1/1 : RUN cd /src && ./build.sh "$(cat VERSION)-custom"
2017-11-30T11:11:39.0152290Z ---> Running in 2ff187d235ae
2017-11-30T11:11:39.3676710Z �[91m/bin/sh: ./build.sh: Permission denied
2017-11-30T11:11:39.6158700Z �[0mThe command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126
2017-11-30T11:11:39.6340170Z ##[error]The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126
2017-11-30T11:11:39.6404080Z ##[error]/usr/bin/docker failed with return code: 126

@michaelshobbs
Copy link
Member

are you copying build.sh from the root of this repo or is that your own script? either way chmod +x that bad boy and all should be good...i think

@trondvh
Copy link
Contributor

trondvh commented Dec 1, 2017

The same for me, building a custom image with gitlab-ci:

Running with gitlab-runner 10.2.0 (0a75cdd1)
  on Docker Runner docker-in-docker 02-3 (vmgir02it) (a0f863e8)
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:2b5312e84355e6e50dd36c61663df237e8f0431f5af003710a7b3d10cd73b6bc for docker service...
Waiting for services to be up and running...
Using docker image sha256:ddaf92ee2c588ceab09a84852e72d0d532164a8efdef915717f5b479eedad79a for predefined container...
Pulling docker image docker:latest ...
Using docker image docker:latest ID=sha256:97e854a6493aedda8bf6e7f0dc256135cb4dbe525d2186655cb45368a42cab9c for build container...
Running on runner-a0f863e8-project-335-concurrent-0 via vmgir02it...
Cloning repository...
Cloning into '/builds/devops/dockers/docker-logspout-kafka'...
Checking out 24a10d3f as master...
Skipping Git submodules setup
$ docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
$ docker build --pull -t "$CI_REGISTRY_IMAGE" .
Sending build context to Docker daemon  36.35kB

Step 1/4 : FROM gliderlabs/logspout:v3.2.3
v3.2.3: Pulling from gliderlabs/logspout
019300c8a437: Pulling fs layer
1b19e7c0b70f: Pulling fs layer
93ff2b51dfee: Pulling fs layer
1b19e7c0b70f: Verifying Checksum
1b19e7c0b70f: Download complete
019300c8a437: Verifying Checksum
019300c8a437: Download complete
93ff2b51dfee: Verifying Checksum
93ff2b51dfee: Download complete
019300c8a437: Pull complete
1b19e7c0b70f: Pull complete
93ff2b51dfee: Pull complete
Digest: sha256:a18d697fbc797d541a45c26c53a855febe0af25728fbc32e77d1e0532af58f1d
Status: Downloaded newer image for gliderlabs/logspout:v3.2.3
# Executing 3 build triggers
 ---> Running in ba8409efd963
/bin/sh: ./build.sh: Permission denied
The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126
ERROR: Job failed: exit code 126

As you are using ONBUILD in the base file, I don't believe that a chmod in the downstream Dockerfile will help, as build.sh is executed by ONBUILD in the base file.

@michaelshobbs
Copy link
Member

I don't think I follow what you're saying. It doesn't matter which dockerfile calls the script as long as the script itself is executable in current docker build context. That being said, I will gladly accept a PR that brings back the RUN chmod +x directive.

@djeeg
Copy link

djeeg commented Feb 3, 2018

Looks fixed, thanks for merging!

...
Status: Downloaded newer image for gliderlabs/logspout:master
[91m# Executing 3 build triggers...
[0mStep 1/1 : COPY ./build.sh /src/build.sh
Step 1/1 : COPY ./modules.go /src/modules.go
Step 1/1 : RUN cd /src && chmod +x ./build.sh && ./build.sh "$(cat VERSION)-custom"
---> Running in 8ef1c975d884
Starting ...
fetch http:https://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http:https://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
(1/49) Installing fakeroot (1.21-r1)
(2/49) Installing sudo (1.8.21_p2-r1)
(3/49) Installing libcap (2.25-r1)
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants