GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.85k stars 1.44k forks source link

Failed to build image when running "apt install -y openjdk-8-jdk" using kaniko on k8s #2729

Open figureair opened 1 year ago

figureair commented 1 year ago

Actual behavior I am trying to use Kaniko to build images on Kubernetes, but I am encountering some issues during the build process. When I try to install openjdk, it throws systemd-related exceptions, whereas the same build is successful with "docker build". Also, when I use Kaniko in the local Docker environment, the build works fine. I would like to know if this is related to Kubernetes and how to resolve such an issue.

Created symlink /etc/systemd/system/getty.target.wants/getty@tty1.service → /lib/systemd/system/getty@.service.
Created symlink /etc/systemd/system/multi-user.target.wants/remote-fs.target → /lib/systemd/system/remote-fs.target.
Created symlink /etc/systemd/system/sysinit.target.wants/systemd-pstore.service → /lib/systemd/system/systemd-pstore.service.
Initializing machine ID from random generator.
Failed to take /etc/passwd lock: Invalid argument
dpkg: error processing package systemd (--configure):
 installed systemd package post-installation script subprocess returned error exit status 1
Setting up dmsetup (2:1.02.185-2) ...
Errors were encountered while processing:
 systemd
E: Sub-process /usr/bin/dpkg returned an error code (1)
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 100

Expected behavior Build successfully.

To Reproduce Steps to reproduce the behavior:

  1. running the kaniko pod with this Dockerfile

Additional Information

ARG PYIM=python:3.8.16-bullseye
# use python 3.8 as default base image
FROM $PYIM

RUN echo 'deb http:deb.debian.org/debian/ sid main' > /etc/apt/sources.list

RUN apt update

RUN dpkg --configure -a

# install openjdk for package download
RUN apt install -y openjdk-8-jdk
JeromeJu commented 1 year ago

Thanks for filing the issue @figureair 🙏 , would you mind providing the inputs of which Kaniko version you are using and which context for this case?

figureair commented 1 year ago

Thanks for filing the issue @figureair 🙏 , would you mind providing the inputs of which Kaniko version you are using and which context for this case?

Thank you for the reminder. I have added more explanations, and at the same time, I have basically imitated the official example for building.

figureair commented 1 year ago

This issue seems to be related to the version of K8S. The original problem occurred in K8S version 1.12. However, when I use a newer version of Kubernetes, this issue does not occur.