GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.23k stars 1.4k forks source link

Executing Kaniko on different container cannot build Dockerfile from alpine image #3195

Open qalinn opened 3 weeks ago

qalinn commented 3 weeks ago

Actual behavior I have created my own docker image based on ubuntu with kaniko executor inside. When I am trying to build Dockerfile based on linux alpine, the kaniko build failed with the following error: "/bin/sh: 1: apk: not found"

Expected behavior Kaniko must be able to build images based on dockerfile using alpine image as based

To Reproduce Steps to reproduce the behavior:

  1. Create your own ubuntu container where to run kaniko. I have used the following dockerfile: FROM gcr.io/kaniko-project/executor:v1.23.0 as kaniko FROM ubuntu:22.04

ENV JAVA_OPTS -XX:-UsePerfData

RUN apt-get update && apt-get install -y vim

WORKDIR /kaniko USER root COPY --from=kaniko /kaniko /kaniko RUN cp /kaniko/executor /kaniko/kanikoexecutor COPY config.json /kaniko/.docker/

ENV HOME /root ENV USER root ENV PATH=$PATH:/kaniko ENV DOCKER_CONFIG=/kaniko/.docker/ ENV SSL_CERT_DIR=/kaniko/ssl/certs

RUN echo '#!/bin/bash \n kanikoexecutor --ignore-path=/opt "$@"' > /kaniko/kaniko-executor && chmod +x /kaniko/kaniko-executor

RUN echo 'FROM node:lts-alpine3.18 AS deps \n RUN apk add --no-cache libc6-compat yarn' >> Dockerfile

  1. Build the previous Dockerfile which contains an example of dockerfile with nodejs alpine version. docker build -f Dockerfile_ubuntu . -t example:1
  2. Run " docker run -it example:1 bash"
  3. On the container execute following command: " /kaniko/kaniko-executor --force --context=. --dockerfile=Dockerfile --ignore-path=/lib --ignore-path=/usr/bin --ignore-path=/usr/lib --ignore-path=/bin --use-new-run=true --no-push"
  4. The results will be: INFO[0004] Args: [-c apk add --no-cache libc6-compat yarn] INFO[0004] Running: [/bin/sh -c apk add --no-cache libc6-compat yarn] /bin/sh: 1: apk: not found

Additional Information