Build image from inside a pod or container It seems pretty easy to build image when I just mount the docker.sock in a container. It's same as what I do on hosts machine. Simply docker build . -t image/name:sometag.
But when I need to do the same from a pod/container in K3s installation, I don't find a way of doing it. Can someone please guide me to something? It has to happen without mounting docker.sock.
If you simply need to build a docker image, I recommend using Kaniko. It allows you to build a docker image without having to expose the docker.sock or running your pods in privileged mode, which introduces potential security vulnerabilities. Per the Kaniko documentation, your spec file would look similar to:
apiVersion: v1
kind: Pod
metadata:
  name: kaniko
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:latest
    args:
    - &quot;--dockerfile=&lt;path to Dockerfile within the build context&gt;&quot;
  restartPolicy: Never