{"id":616,"date":"2026-10-03T12:00:00","date_gmt":"2026-10-03T12:00:00","guid":{"rendered":"https:\/\/konteynerium.com\/index.php\/2026\/10\/03\/buildkit-build-cache-hizli-docker-build\/"},"modified":"2026-10-03T12:00:00","modified_gmt":"2026-10-03T12:00:00","slug":"buildkit-build-cache-hizli-docker-build","status":"publish","type":"post","link":"https:\/\/konteynerium.com\/index.php\/2026\/10\/03\/buildkit-build-cache-hizli-docker-build\/","title":{"rendered":"Build Cache ve BuildKit: Docker Build&#8217;i H\u0131zland\u0131rman\u0131n Yollar\u0131"},"content":{"rendered":"<p>Bir de\u011fi\u015fiklik yapt\u0131n\u0131z, <code>docker build<\/code> \u00e7al\u0131\u015ft\u0131rd\u0131n\u0131z ve ba\u011f\u0131ml\u0131l\u0131klar yeniden indiriliyor. Her seferinde. Dakikalar ak\u0131p gidiyor. Docker&#8217;\u0131n build \u00f6nbelle\u011fi bunu \u00f6nlemek i\u00e7in tasarlanm\u0131\u015ft\u0131r, ama do\u011fru kullanmak i\u00e7in nas\u0131l \u00e7al\u0131\u015ft\u0131\u011f\u0131n\u0131 bilmeniz gerekir. Bu yaz\u0131da katman \u00f6nbelle\u011finin mant\u0131\u011f\u0131n\u0131, <code>--mount=type=cache<\/code> ile paket \u00f6nbelle\u011fini ve CI&#8217;da \u00f6nbelle\u011fi payla\u015fmay\u0131 anlat\u0131yoruz.<\/p>\n<h2>Katman \u00f6nbelle\u011fi nas\u0131l \u00e7al\u0131\u015f\u0131r?<\/h2>\n<p>BuildKit her talimat\u0131 \u00e7al\u0131\u015ft\u0131rmadan \u00f6nce \u015funa bakar: &#8220;Bu talimat ve girdileri daha \u00f6nce ayn\u0131 m\u0131yd\u0131?&#8221; Ayn\u0131ysa sonucu \u00f6nbellekten al\u0131r (<code>CACHED<\/code>). Bir talimat ge\u00e7ersiz kal\u0131rsa (talimat de\u011fi\u015fti ya da <code>COPY<\/code> etti\u011fi dosyalar de\u011fi\u015fti) <strong>ondan sonraki t\u00fcm katmanlar<\/strong> yeniden \u00e7al\u0131\u015f\u0131r. Bu y\u00fczden talimat s\u0131ras\u0131 \u00f6nemlidir: <em>az de\u011fi\u015fenler \u00fcstte, \u00e7ok de\u011fi\u015fenler altta<\/em>.<\/p>\n<pre><code>FROM temel-imaj\nWORKDIR \/app\nCOPY deps.txt .                       # ba\u011f\u0131ml\u0131l\u0131k listesi: nadiren de\u011fi\u015fir\nRUN kur-bagimliliklari deps.txt       # pahal\u0131 ad\u0131m\nCOPY app.txt .                        # kaynak kod: s\u0131k de\u011fi\u015fir\nRUN derle<\/code><\/pre>\n<h2>Denemeyle g\u00f6relim<\/h2>\n<p>Yukar\u0131daki Dockerfile&#8217;\u0131 build ettikten sonra iki farkl\u0131 de\u011fi\u015fiklik yapt\u0131k. \u00d6nce yaln\u0131zca kaynak kodu (<code>app.txt<\/code>) de\u011fi\u015ftirdik:<\/p>\n<pre><code>#6 [2\/6] WORKDIR \/app                 CACHED\n#7 [3\/6] COPY deps.txt .              CACHED\n#8 [4\/6] RUN kur-bagimliliklari ...   CACHED\n#9 [5\/6] COPY app.txt .               (yeniden \u00e7al\u0131\u015ft\u0131)\n#10 [6\/6] RUN derle                   (yeniden \u00e7al\u0131\u015ft\u0131)<\/code><\/pre>\n<p>Pahal\u0131 ba\u011f\u0131ml\u0131l\u0131k ad\u0131m\u0131 \u00f6nbellekten geldi. Sonra ba\u011f\u0131ml\u0131l\u0131k listesini (<code>deps.txt<\/code>) de\u011fi\u015ftirdik:<\/p>\n<pre><code>#6 [2\/6] WORKDIR \/app                 CACHED\n#7 [3\/6] COPY deps.txt .              (yeniden \u00e7al\u0131\u015ft\u0131)\n#8 [4\/6] RUN kur-bagimliliklari ...   (yeniden \u00e7al\u0131\u015ft\u0131)\n#9 [5\/6] COPY app.txt .               (yeniden \u00e7al\u0131\u015ft\u0131)\n#10 [6\/6] RUN derle                   (yeniden \u00e7al\u0131\u015ft\u0131)<\/code><\/pre>\n<p>Bu kez <code>COPY deps.txt<\/code>&#8216;den itibaren <em>her \u015fey<\/em> yeniden \u00e7al\u0131\u015ft\u0131 \u2014 kural bu: bir katman ge\u00e7ersiz olursa alt\u0131ndakilerin hepsi ge\u00e7ersiz olur. Bunun do\u011fru kullan\u0131m\u0131, ba\u011f\u0131ml\u0131l\u0131k dosyalar\u0131n\u0131 (<code>package.json<\/code>, <code>requirements.txt<\/code>, <code>go.mod<\/code>) kaynak koddan <em>\u00f6nce<\/em> kopyalamakt\u0131r; b\u00f6ylece g\u00fcnl\u00fck kod de\u011fi\u015fiklikleri ba\u011f\u0131ml\u0131l\u0131k kurulumunu tetiklemez.<\/p>\n<h2>\u00d6nbellek ba\u011flama (cache mount): paket indirmelerini kal\u0131c\u0131la\u015ft\u0131r\u0131n<\/h2>\n<p>Katman \u00f6nbelle\u011fi, bir ba\u011f\u0131ml\u0131l\u0131k de\u011fi\u015fti\u011finde t\u00fcm kurulum ad\u0131m\u0131n\u0131 yeniden \u00e7al\u0131\u015ft\u0131r\u0131r. <code>RUN --mount=type=cache<\/code> ile paket y\u00f6neticisinin \u00f6nbellek dizinini build&#8217;ler aras\u0131 <strong>kal\u0131c\u0131<\/strong> hale getirebilirsiniz; b\u00f6ylece de\u011fi\u015fen bir ba\u011f\u0131ml\u0131l\u0131kta bile yaln\u0131zca fark\u0131 indirirsiniz:<\/p>\n<pre><code>RUN --mount=type=cache,target=\/root\/.npm npm ci\nRUN --mount=type=cache,target=\/var\/cache\/apt apt-get update &amp;&amp; apt-get install -y paket<\/code><\/pre>\n<p>Davran\u0131\u015f\u0131 do\u011frulamak i\u00e7in bir saya\u00e7 denemesi yapt\u0131k: komut metnini her seferinde de\u011fi\u015ftirerek (katman \u00f6nbelle\u011fini atlatarak) \u00fc\u00e7 ard\u0131\u015f\u0131k build \u00e7al\u0131\u015ft\u0131rd\u0131k, komut cache dizinindeki bir dosyay\u0131 bir art\u0131r\u0131yor:<\/p>\n<pre><code>build 1:  2\nbuild 2:  3\nbuild 3:  4<\/code><\/pre>\n<p>Saya\u00e7 build&#8217;ler aras\u0131nda <strong>artarak<\/strong> devam etti: \u00f6nbellek dizini imaj\u0131n bir par\u00e7as\u0131 olmad\u0131\u011f\u0131 halde build&#8217;ler aras\u0131nda ya\u015f\u0131yor. \u00d6nemli ayr\u0131m \u015fu: cache mount&#8217;taki veri nihai imaja <em>girmez<\/em> (imaj\u0131 \u015fi\u015firmez) ve ba\u015fka makinelere ta\u015f\u0131nmaz; yaln\u0131zca o build motorunun yerel \u00f6nbelle\u011fidir.<\/p>\n<h2>\u00d6nbelle\u011fi CI&#8217;da payla\u015fmak<\/h2>\n<p>CI sunucular\u0131nda her build temiz bir makinede ba\u015flad\u0131\u011f\u0131 i\u00e7in yerel \u00f6nbellek yoktur. \u00c7\u00f6z\u00fcm, \u00f6nbelle\u011fi d\u0131\u015fa aktar\u0131p bir sonraki build&#8217;de i\u00e7e almakt\u0131r:<\/p>\n<pre><code># \u00d6nbelle\u011fi bir dizine (veya registry'ye) yaz\ndocker buildx build --cache-to type=local,dest=.\/cache .\n\n# Sonraki build'de oradan oku\ndocker buildx build --cache-from type=local,src=.\/cache .\n\n# Registry \u00fczerinden payla\u015f\u0131m\ndocker buildx build \\\n  --cache-to   type=registry,ref=registry.ornek.com\/uygulama:cache \\\n  --cache-from type=registry,ref=registry.ornek.com\/uygulama:cache .<\/code><\/pre>\n<p>Dok\u00fcmantasyona g\u00f6re registry, GitHub Actions (<code>type=gha<\/code>), S3 ve Azure Blob arka u\u00e7lar\u0131 desteklenir. GitHub Actions \u00f6rne\u011fi i\u00e7in <a href=\"https:\/\/konteynerium.com\/index.php\/2026\/08\/14\/cicd-ile-docker-github-actions-otomatik-build-deploy\/\">CI\/CD ile Docker<\/a> yaz\u0131s\u0131na bak\u0131n. Yukar\u0131daki <code>type=local<\/code> yazma komutunu varsay\u0131lan Docker 29.4 builder&#8217;\u0131nda \u00e7al\u0131\u015ft\u0131r\u0131p \u00f6nbellek manifestinin yaz\u0131ld\u0131\u011f\u0131n\u0131 do\u011frulad\u0131k.<\/p>\n<h2>\u00d6nbelle\u011fi bozan yayg\u0131n hatalar<\/h2>\n<ul>\n<li><strong><code>COPY . .<\/code> en \u00fcstte:<\/strong> herhangi bir dosya de\u011fi\u015fince alt\u0131ndaki her \u015fey yeniden \u00e7al\u0131\u015f\u0131r. \u00d6nce ba\u011f\u0131ml\u0131l\u0131k dosyalar\u0131n\u0131 kopyalay\u0131n. Gereksiz dosyalar\u0131 <a href=\"https:\/\/konteynerium.com\/index.php\/2026\/09\/30\/dockerignore-ve-build-baglami-docker-build-neden-yavas\/\">.dockerignore<\/a> ile ba\u011flamdan \u00e7\u0131kar\u0131n.<\/li>\n<li><strong>Zamana ba\u011fl\u0131 komutlar:<\/strong> <code>RUN date &gt; build-time<\/code> gibi komutlar her seferinde farkl\u0131 sonu\u00e7 \u00fcretir; \u00f6nbellek mant\u0131kl\u0131 \u00e7al\u0131\u015fmaz.<\/li>\n<li><strong>Tek <code>RUN<\/code> i\u00e7inde \u00e7ok fazla i\u015f:<\/strong> k\u00fc\u00e7\u00fck bir de\u011fi\u015fiklikte hepsi yeniden \u00e7al\u0131\u015f\u0131r. Mant\u0131ksal olarak ayr\u0131labilen ad\u0131mlar\u0131 b\u00f6l\u00fcn.<\/li>\n<li><strong>\u00d6nbelle\u011fi s\u00fcrekli s\u0131f\u0131rlamak:<\/strong> <code>--no-cache<\/code> yaln\u0131zca ger\u00e7ekten temiz bir build gerekti\u011finde (\u00f6rne\u011fin g\u00fcvenlik g\u00fcncellemelerini zorlamak i\u00e7in) kullan\u0131n.<\/li>\n<\/ul>\n<div class=\"callout\">\n  <span class=\"glyph\">i<\/span><\/p>\n<p>\u00d6nbellek ile g\u00fcncellik aras\u0131nda denge vard\u0131r: \u00f6nbellekli bir build, <code>apt-get update<\/code> gibi ad\u0131mlardaki g\u00fcvenlik g\u00fcncellemelerini otomatik almaz. D\u00fczenli aral\u0131klarla <code>--no-cache<\/code> veya <code>--pull<\/code> ile temiz build al\u0131n.<\/p>\n<\/div>\n<h2>H\u0131zl\u0131 kontrol listesi<\/h2>\n<ul>\n<li>Ba\u011f\u0131ml\u0131l\u0131k dosyalar\u0131 kaynak koddan \u00f6nce mi kopyalan\u0131yor?<\/li>\n<li>Paket y\u00f6neticisi i\u00e7in <code>--mount=type=cache<\/code> kullan\u0131yor musunuz?<\/li>\n<li>CI&#8217;da <code>--cache-from\/--cache-to<\/code> tan\u0131ml\u0131 m\u0131?<\/li>\n<li>Build ba\u011flam\u0131 k\u00fc\u00e7\u00fck m\u00fc?<\/li>\n<\/ul>\n<p>\u0130maj boyutunu k\u00fc\u00e7\u00fcltmek i\u00e7in <a href=\"https:\/\/konteynerium.com\/index.php\/2026\/10\/02\/multi-stage-build-ile-kucuk-imajlar\/\">Multi-Stage Build<\/a> yaz\u0131s\u0131na, katman kavram\u0131n\u0131n temeline <a href=\"https:\/\/konteynerium.com\/index.php\/2026\/09\/29\/docker-imaji-ve-container-farki-katmanlar-etiketler-yasam-dongusu\/\">\u0130maj ve Container Fark\u0131<\/a> yaz\u0131s\u0131na bak\u0131n.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker build her seferinde ba\u011f\u0131ml\u0131l\u0131klar\u0131 yeniden mi indiriyor? Katman \u00f6nbelle\u011finin mant\u0131\u011f\u0131n\u0131, cache mount ile paket \u00f6nbelle\u011fini ve CI&#8217;da \u00f6nbelle\u011fi payla\u015fmay\u0131 ger\u00e7ek build \u00e7\u0131kt\u0131lar\u0131yla anlat\u0131yoruz.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"seviye":[8],"class_list":["post-616","post","type-post","status-publish","format-standard","hentry","category-docker-derinlemesine","seviye-orta"],"_links":{"self":[{"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/posts\/616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/comments?post=616"}],"version-history":[{"count":0,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/posts\/616\/revisions"}],"wp:attachment":[{"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/media?parent=616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/categories?post=616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/tags?post=616"},{"taxonomy":"seviye","embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/seviye?post=616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}