1

Newbie to kaniko, and try to build docker images in ubuntu docker host.

I have a local Dockerfile and main.go app

# Dockefile
FROM golang:1.10.3-alpine AS build
ADD . /src
RUN cd /src && go build -o app

FROM alpine
WORKDIR /app
COPY --from=build /src/app /app/
CMD [ "./app" ]
#main.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

And in command line, i run

docker run -it  -v $(pwd):/usr \
   gcr.io/kaniko-project/executor:latest \
   --dockerfile=Dockerfile --context=/usr --no-push

Unfortunately, I got error like below

...
INFO[0006] Skipping paths under /proc, as it is a whitelisted directory
INFO[0006] Using files from context: [/usr]
INFO[0006] ADD . /src
INFO[0006] Taking snapshot of files...
INFO[0006] RUN cd /src && go build -o app
INFO[0006] cmd: /bin/sh
INFO[0006] args: [-c cd /src && go build -o app]
/bin/sh: go: not found
error building image: error building stage: waiting for process to exit: exit status 127

What's wrong? (docker version 18.09.0)

Larry Cai
  • 55,923
  • 34
  • 110
  • 156

1 Answers1

2

You need to use different path for context in kaniko. Your command to run this build should look like this:

docker run -it  -v $(pwd):/context \
   gcr.io/kaniko-project/executor:latest \
   --dockerfile=Dockerfile --context=/context --no-push

In your command with /usr as context kaniko where overriding this path in all of Dockerfiles and in golang image, go is located in /usr path thats why it couldn't find it then

# which go
/usr/local/go/bin/go
ttomalak
  • 1,936
  • 13
  • 19