kubernetes-up-and-running / kuard

Demo app for Kubernetes Up and Running book
Apache License 2.0
1.56k stars 535 forks source link

build.sh not found when doing docker build #30

Open zhoucengchao opened 4 years ago

zhoucengchao commented 4 years ago

Hi, I followed the procedures of multi-stage image build described in chapter 2 but was getting the build.sh not found problem.

$ docker build -t kuard . ....... Step 11/12 : RUN build/build.sh ---> Running in 1119265327a0 /bin/sh: build/build.sh: not found

Did I miss anything or should I modify something rather than copy paste the content of the Dockerfile? Do I need to clone the the ./kuard to /go/src/github.com/kubernetes-up-and-running/kuard onto my Mac local filesystem? / is read-only on macOS Catalina BTW. Thanks!

jastis77 commented 4 years ago

I have the exact same issue . Running Docker Desktop for Windows 2.2. Step 10/14 : RUN build/build.sh ---> Running in 32c9d6d4aff7 /bin/sh: build/build.sh: not found The command '/bin/sh -c build/build.sh' returned a non-zero code: 127

wbanguna commented 4 years ago

Try this:

1) go get github.com/kubernetes-up-and-running/kuard 2) cd into directory, probably GOPATH/src/github.com/kubernetes-up-and-running/kuard 3) docker build -t kuard .

arkfen commented 4 years ago

Try this:

  1. go get github.com/kubernetes-up-and-running/kuard
  2. cd into directory, probably GOPATH/src/github.com/kubernetes-up-and-running/kuard
  3. docker build -t kuard .

even doing so still getting this:

Step 9/14 : ENV VERSION=test ---> Running in f9a4a90a95dc Removing intermediate container f9a4a90a95dc ---> 2868f0e1957c Step 10/14 : RUN build/build.sh ---> Running in c8ca9ae76872 /bin/sh: build/build.sh: not found The command '/bin/sh -c build/build.sh' returned a non-zero code: 127

jbeda commented 4 years ago

Sorry I haven't gotten to this! I'll try to fix it this weekend.

funkybrown commented 4 years ago

yes me too it looks like its not copying the build directory when you ls the working directory or something

andyw8 commented 4 years ago

I'm also running into this.

❯ docker -v
Docker version 19.03.1, build 74b1e89
andyw8 commented 4 years ago

Update: If I download this repo as a zip, then I'm able to build the image, after setting chmod +x on build/build.sh.

I think the chapter is assuming the necessary directories (e.g. build/ and client/) are already present on your local machine alongside the Dockerfile.

jbeda commented 4 years ago

Hey all -- i'm having a hard time reproducing this!

Some quick questions to help narrow this down:

As for me, I'm doing a git clone outside of my $GOPATH, going into that directory and doing a simple docker build -t kuard .. I'm on macOS Catalina with Docker version 19.03.5, build 633a0ea.

Or is it that the instructions in the book don't make it clear that you need the whole repo? (If so I'm sorry about that!)

jbeda commented 4 years ago

I created a quick video for how it works for me. Hopefully this'll be helpful for folks: https://www.youtube.com/watch?v=2DB74KoZCNU&feature=youtu.be

arkfen commented 4 years ago

First of all thanks for your hard work and great video... Secondly - unfortunately after following your steps I got the same result as you can see... I have the same version of the Docker.. I ignored the instruction of cloning to the folder our of the Go path because as far as I know I do not have GO installed on this PC at all.. I run Win 10 Pro and I have cloned to C:\Code\kuard and I also pruned the docker prior to the build... hm... any ideas?

I tried few times before - started with just book instructions and then switched to this Git repo and cloning...

image

arkfen commented 4 years ago

PS now I am pretty new to docker and I have absolutely no experience with GO... now I am not sure - perhaps PC must have GO installed after all in order to build this image? Or when it downloads alpine - go image it is building other stuff already from the container and I no need GO or even Node to be installed locally?

wiardvanrij commented 4 years ago

@arkfen Could you check in Docker for Windows if your C: drive is actually shared?

Docker for Windows -> Settings -> Shared Drivers -> Enabled for C:

arkfen commented 4 years ago

yes, I think so... please double check with my screenshot if this is what you mean

image

jbeda commented 4 years ago

Hey all -- clearly this is an issue that only happens on Windows. I'm traveling this week and don't have easy access to a windows machine (should probably set up a VM). I'll try and dig in this weekened.

Chike-O commented 4 years ago

I am experiencing the same issue; I am running Docker on a Windows 10 machine. Please let us know your findings when you try it out on Windows 10.

harkanwals commented 4 years ago

I had the same issue on macOS Catalina, version 10.15.3. Docker version 19.03.5, build 633a0ea.

Just posting it here in case anyone comes with same issue from the book.

I was running the script directly from the book, without cloning the Git repo.

Then, I cloned the repo, as per directions from @jbeda and just ran the Dockerfile there and it worked like a charm. Hopefully, this helps someone.

aryo-ps commented 4 years ago

I am also facing this issue on Centos 7. this issue comes when you running the Dockerfile outside the repo directory. make sure you have installed git.

Solved:

  1. git clone https://github.com/kubernetes-up-and-running/kuard.git
  2. cd /kuard
  3. run command make
  4. run you Dockerfile inside Kuard directory
stanlearn777 commented 4 years ago

I am experiencing the same issue; I am running Docker on a Windows 10 Pro machine. Please, let me know of your findings on Windows 10 Pro. Thanks.

djfrmd commented 4 years ago

There are windows line endings in the repo. It is not working for windows because of the shebang in build/build.sh

If you remove the ^M from all lines in the *.sh files it works fine on windows. The link below talks about how to fix this for the repo.

https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings#per-repository-settings

os-learner commented 4 years ago

I'm also getting the same exact error message. Please advise. I'm trying to build kuard on a windows PC.

Step 10/14 : RUN build/build.sh ---> Running in 1efb2a68c367 /bin/sh: build/build.sh: not found The command '/bin/sh -c build/build.sh' returned a non-zero code: 127

image

os-learner commented 4 years ago

arkfen, Is it working for you? jbode, Any advise on how to get this working?

djfrmd commented 4 years ago

@os-learner can you change all CRLFs to LFs in the *.sh files and re-run? I created a pull request with this done.

I am relatively certain this is the issue most people are seeing on Windows devices where git-for-windows is handling line endings for the repo based on user settings.

os-learner commented 4 years ago

@djfrmd , Thanks. I downloaded Notepad++ and did extended search to find "\r\n" with \n" and saved the build.sh file. I executed build then and it worked without any issues. Thanks for your help.

isaacsgi commented 4 years ago

You can also do this in VS Code: https://stackoverflow.com/questions/39525417/visual-studio-code-how-to-show-line-endings :)

xt94c4t9ce commented 4 years ago

I ran in to this same situation.

Or is it that the instructions in the book don't make it clear that you need the whole repo?

In my case this was indeed the problem. If the book told me to download the repository and run docker inside of it, I missed this part. I guess the download may be obvious to folks with docker experience, but I'm new to it. Thanks and have a great day!

philippw commented 4 years ago

@jbeda Please integrate the line-endings fix #31. This saves a lot of headaches for Windows 10 users.

This fix prevents git from converting line-endings on checkout.

For everyone else: if you get docker /bin/sh: build/build.sh: not found you are probably using docker-cli or Docker for Windows and git is configured to convert CR (Unix line-endings) to CR/LF (Windows line-endings) on checkout.

All you need to do to resolve this, is to convert build/build.sh from using CR instead of CR/LF. See comments above, to find out on how to do this for several popular editors.

Niedman commented 4 years ago

I had the same issue so I clone the repository and you will notice that there is already a Dockerfile with multistage similar to the one you allegedly have created just before. You can delete yours or just replace it by the current Dockerfile.

When inside the folder kuard you can simply run the command that is on the book: docker build -t kuard .

Hope it helps.

arkfen commented 3 years ago

arkfen, Is it working for you? jbode, Any advise on how to get this working?

oh yeah! thanks a lot! it worked just after changing line ending in the notepad++ - took me 20 seconds )) I just did not check the issue for few months and finally found time to do it... and fix it. I hope everyone else got the issue solved... I am not pro regarding line endings for different OSs but if there is a way to leave it the way which works everywhere - it would be nice.. then it would work on Windows right away

image

simcikdt commented 3 years ago

I downloaded kuard-master from GitHub, copied the multi-stage Dockerfile to a new directory on my Windows 10 laptop, then tried running the Docker build, which still failed on the build.sh step. As an alternative, I changed into the kuard-master (unzipped) directory and did a Docker build on the original (cloned/downloaded) multi-stage Dockerfile there and it worked!

I also tried doing a search+replace on the CRLF chars on copied/pasted code from an ebook, but that didn't work ultimately either.

weseifert commented 3 years ago

I had the same error on Mac OS Big Sur. I cloned the repo in the ~/go/src/ path (e.g. "git clone https://github.com/kubernetes-up-and-running/kuard.git") and ran docker build from the kuard directory it found the shell script and executed correctly.

david-hatton commented 3 years ago

If you're running on Windows, ensure you're not converting the line endings to Windows. Easiest way to do this, which avoids all the post processing mentioned above is to configure it when you clone the repo, e.g.

git clone https://github.com/kubernetes-up-and-running/kuard.git --config core.autocrlf=input

See here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

(Search for autocrlf)

NRKirby commented 3 years ago

git clone https://github.com/kubernetes-up-and-running/kuard.git --config core.autocrlf=input

I can confirm that this works.

I can now run the docker build command without it erroring when it tries to run build.sh

shan-wan commented 3 years ago

Yes, just append this line:

RUN git clone https://github.com/kubernetes-up-and-running/kuard .

after the WORKDIR line

# Get dependencies for Go part of build
RUN go get -u github.com/jteeuwen/go-bindata/...
RUN go get github.com/tools/godep

WORKDIR /go/src/github.com/kubernetes-up-and-running/kuard
# append this line
RUN git clone https://github.com/kubernetes-up-and-running/kuard .

# Copy all sources in
COPY . .