kubernetes - Diagnosing a build error in Docker, from an example in a book - Stack Overflow

admin2025-04-29  2

I'm running an example from the O'Reilly book Kubernetes Up & Running, but it gives me a build error, which I'm trying to debug.

When I type docker build -t kuard . I get this build error:

 => ERROR [9/9] RUN build/build.sh                                                                                                              
------                                                                                                                                               
 > [9/9] RUN build/build.sh:
0.162 /bin/sh: build/build.sh: not found
------

To begin my debugging, I decided to look at what's in the directory, so I inserted the pwd and ls -aF commands. This approach is suggested by the Docker help page at

It didn't help. Now my output looks like this:

 => CACHED [6/9] COPY . .          0.0s
 => CACHED [7/9] RUN pwd           0.0s
 => CACHED [8/9] RUN ls -aF        0.0s
 => ERROR [9/9] RUN build/build.sh 0.2s
------
 > [9/9] RUN build/build.sh:
0.175 /bin/sh: build/build.sh: not found
------

So my narrow question is this: How do I get the results of the pwd and ls -aF commands in Docker? But my broader question is this: How do I debug a Docker file?

Here's the whole Docker file. The directory has no other contents.

FROM golang:1.11-alpine

# Install Node and NPM
RUN apk update && apk upgrade && apk add --no-cache git nodejs bash npm

# Get dependencies for Go part of build
RUN go get -u github/jteeuwen/go-bindata/...
RUN go get github/tools/godep
WORKDIR /go/src/github/kubernetes-up-and-running/kuard

# Copy all sources in
COPY . .

# This is a set of variables that the build script expects
ENV VERBOSE=0
ENV PKG=github/kubernetes-up-and-running/kuard
ENV ARCH=amd64
ENV VERSION=test

# Do the build. This script is part of incoming sources.
RUN pwd
RUN ls -aF
RUN build/build.sh
CMD [ "/go/bin/kuard" ]

I also tried commenting out the RUN build/build.sh command, but I still didn't see the results of the pwd or ls -aF commands.

I'm running an example from the O'Reilly book Kubernetes Up & Running, but it gives me a build error, which I'm trying to debug.

When I type docker build -t kuard . I get this build error:

 => ERROR [9/9] RUN build/build.sh                                                                                                              
------                                                                                                                                               
 > [9/9] RUN build/build.sh:
0.162 /bin/sh: build/build.sh: not found
------

To begin my debugging, I decided to look at what's in the directory, so I inserted the pwd and ls -aF commands. This approach is suggested by the Docker help page at https://www.docker.com/blog/how-to-fix-and-debug-docker-containers-like-a-superhero/#Docker%20Build

It didn't help. Now my output looks like this:

 => CACHED [6/9] COPY . .          0.0s
 => CACHED [7/9] RUN pwd           0.0s
 => CACHED [8/9] RUN ls -aF        0.0s
 => ERROR [9/9] RUN build/build.sh 0.2s
------
 > [9/9] RUN build/build.sh:
0.175 /bin/sh: build/build.sh: not found
------

So my narrow question is this: How do I get the results of the pwd and ls -aF commands in Docker? But my broader question is this: How do I debug a Docker file?

Here's the whole Docker file. The directory has no other contents.

FROM golang:1.11-alpine

# Install Node and NPM
RUN apk update && apk upgrade && apk add --no-cache git nodejs bash npm

# 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

# Copy all sources in
COPY . .

# This is a set of variables that the build script expects
ENV VERBOSE=0
ENV PKG=github.com/kubernetes-up-and-running/kuard
ENV ARCH=amd64
ENV VERSION=test

# Do the build. This script is part of incoming sources.
RUN pwd
RUN ls -aF
RUN build/build.sh
CMD [ "/go/bin/kuard" ]

I also tried commenting out the RUN build/build.sh command, but I still didn't see the results of the pwd or ls -aF commands.

Share Improve this question edited Jan 7 at 2:07 MiguelMunoz asked Jan 7 at 0:51 MiguelMunozMiguelMunoz 5,0023 gold badges45 silver badges58 bronze badges 10
  • Did you check this: stackoverflow.com/questions/52233182/… ? – Raghavendra N Commented Jan 7 at 1:39
  • Your question omits key details including the content of the folder in which your Dockerfile exists; the Dockerfile COPY . . expects (I think the cloned source of kuard). What command are you using to build the container. If docker or podman, you can append --no-cache to stop layers being cached during the build thereby omitting your debugging output. – DazWilkin Commented Jan 7 at 1:58
  • @raghavendra-n Thank you for the link. That will probably be useful in the future, but since this is a build issue, and not a run issue, it didn't help. For example, when I type docker ps -a, I don't see any images, because, of course, my build failed. – MiguelMunoz Commented Jan 7 at 1:59
  • @DazWilkin As I said in my description, there isn't anything else in my directory besides the Dockerfile. The example from the book didn't include any other source. I'm assuming the source comes from the RUN go get ... commands in the build file. I'm building using docker build -t kuard . Thanks for pointing that out. I will add it to my description. – MiguelMunoz Commented Jan 7 at 2:06
  • Does build/build.sh exist in your local source tree? What is the very first line of the script? (If it's #!/bin/bash, Alpine-based images don't have bash.) Is there any chance you're working on a Windows host and the file has DOS line endings (which would make the interpreter be /bin/sh\r)? – David Maze Commented Jan 7 at 2:11
 |  Show 5 more comments

1 Answer 1

Reset to default 1

Thanks you to DazWilkin for debugging my build. Now that I can build, I can see how to get the output of the pwd and ls -aF commands. When I build, the output ends with this line:

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/c92k(moreGarbage)...

When I copy that URL into my browser, it opens my docker-desktop and displays my build output. The log button shows, among other things, the output of the pwd and ls -aF commands.

转载请注明原文地址:http://anycun.com/QandA/1745936768a91361.html