Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Kaniko]Hướng dẫn build image docker chạy trong container

Posted on June 6, 2021December 20, 2023 By nim No Comments on [Kaniko]Hướng dẫn build image docker chạy trong container

Sử dụng Kaniko image container bên container hay trong k8s.

Video giải thích:

Các thông tin repository push image lên repository (docker hub, harbor)

kubectl create -n kanik secret \
docker-registry regcred \
--docker-server=https://docker.nimtechnology.com \
--docker-username=nim \
--docker-password=123456 \
--docker-email=mr.nim94@gmail.com

Manifest Pop và run k8s.
Pod này sẽ clone code từ git, check login vào repo.
Build image theo Dockerfile rồi push lên docker hub.

apiVersion: v1
kind: Pod
metadata:
  name: kaniko
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:debug
    args: ["--context=git://github.com/vfarcic/kaniko-demo",
            "--destination=docker.nimtechnology.com/hometest/devops-toolkit:1.0.0"]
    volumeMounts:
      - name: kaniko-secret
        mountPath: /kaniko/.docker
  restartPolicy: Never
  volumes:
    - name: kaniko-secret
      secret:
        secretName: regcred
        items:
          - key: .dockerconfigjson
            path: config.json

Đây là log chạy

Sau khi pod chạy xong.

Links tham khảo thêm

https://gist.github.com/vfarcic/627fcfbfbc17a683a70210947e02eaa3

https://github.com/vfarcic/kaniko-demo

Contents

Toggle
  • Build image docker with Kaniko and Argo Workflow.
    • Example 1: Basic Use
    • Example 2: Nested Dockerfile

Build image docker with Kaniko and Argo Workflow.

    - name: build
      inputs:
        parameters:
          - name: oci-image
            value: ""
          - name: oci-tag
            value: ""
      container:
        image: gcr.io/kaniko-project/executor:latest
        args:
          - --context=/workdir/tools
          - --dockerfile=integration_test/docker/Dockerfile
          - --no-push
          - --tar-path=/workdir/.tar
        workingDir: /workdir
        volumeMounts:
          - name: workdir
            mountPath: /workdir

Certainly! Let’s delve into examples to illustrate how the --context and --dockerfile arguments are used with Kaniko, a tool for building Docker images.

Example 1: Basic Use

Suppose you have a project with the following structure:

/myproject
│
├── Dockerfile
└── src
    ├── app.py
    └── requirements.txt
  • Dockerfile: Contains instructions to build your Docker image.
  • src: Directory containing your application code.

In this case, the Dockerfile is in the root of your project (/myproject). To build this with Kaniko, your arguments might look like:

args:
  - --context=/myproject
  - --dockerfile=Dockerfile
  • --context=/myproject: Tells Kaniko that the build context (source files including the Dockerfile) is located in the /myproject directory.
  • --dockerfile=Dockerfile: Specifies that the Dockerfile is named “Dockerfile” and is located at the root of the context directory.

Example 2: Nested Dockerfile

Consider a more complex project structure:

/myproject
│
├── app
│   └── src
│       ├── app.py
│       └── requirements.txt
└── docker
    └── python
        └── Dockerfile

Here, the Dockerfile is not in the root but inside a nested directory (/myproject/docker/python). To build this, your Kaniko arguments would change:

args:
  - --context=/myproject
  - --dockerfile=docker/python/Dockerfile
  • --context=/myproject: The build context includes the entire /myproject directory, encompassing both the application source code and the Dockerfile.
  • --dockerfile=docker/python/Dockerfile: Specifies the path to the Dockerfile relative to the context directory.

In this second example, although the Dockerfile is not in the root of the context, Kaniko can still locate it because you provide the relative path to the Dockerfile from the context’s root.

These examples demonstrate how the --context and --dockerfile arguments are used to tell Kaniko where to find the Dockerfile and the build context in different project structures. This flexibility allows Kaniko to be integrated into various CI/CD workflows, accommodating a wide range of project layouts.

Kubernetes & Container

Post navigation

Next Post: [Jenkins – Kubernestes] Jenkins tạo Jenkins slave trên Kubernetes

More Related Articles

[ArgoCD] Cài đặt argocd cli và connect với ArgoCD ArgoCD
[Istio] Fix lỗi validationController khi sử dụng istio-operator [revision] cài đặt istio. Isito-EnvoyFilter
[Istio-Multi Cluster] Tutorial is very detailed to install Primary-Remote on different networks Isito-EnvoyFilter
[Kubernetes] Lesson4: k8s easy – Pob Lifecycle, Image registry, init Container Kubernetes & Container
[Helm Chart] Tìm hiểu – (gạch giữa), _ (gạch dưới), dấu chấm “.” trong helm chart Helm Chart
[Kubernetes] How to delete Persistent Volume is Terminating and very stubborn Kubernetes

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [AWS/EKS] Cache Docker image to accelerate EKS container deployment. July 10, 2025
  • [Laravel] Laravel Helpful June 26, 2025
  • [VScode] Hướng dẫn điều chỉnh font cho terminal June 20, 2025
  • [WordPress] Hướng dấn gửi mail trên WordPress thông qua gmail. June 15, 2025
  • [Bitbucket] Git Clone/Pull/Push with Bitbucket through API Token. June 12, 2025

Archives

  • July 2025
  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.