{"id":203,"date":"2026-05-01T12:00:00","date_gmt":"2026-05-01T12:00:00","guid":{"rendered":"https:\/\/konteynerium.com\/?p=203"},"modified":"2026-10-06T11:34:00","modified_gmt":"2026-10-06T11:34:00","slug":"dockerfile-yazmaya-giris","status":"publish","type":"post","link":"https:\/\/konteynerium.com\/index.php\/2026\/05\/01\/dockerfile-yazmaya-giris\/","title":{"rendered":"Dockerfile Yazmaya Giri\u015f: Kendi \u0130maj\u0131n\u0131z\u0131 Olu\u015fturun"},"content":{"rendered":"<p>Bir Dockerfile, Docker&#8217;a bir imaj\u0131n nas\u0131l in\u015fa edilece\u011fini ad\u0131m ad\u0131m anlatan metin tabanl\u0131 bir tariftir. Her sat\u0131r bir katman (layer) olu\u015fturur ve bu katmanlar \u00f6nbelle\u011fe al\u0131narak sonraki build&#8217;lerin \u00e7ok daha h\u0131zl\u0131 olmas\u0131n\u0131 sa\u011flar.<\/p>\n<h2>Basit bir Node.js uygulamas\u0131 i\u00e7in Dockerfile<\/h2>\n<p>A\u015fa\u011f\u0131daki \u00f6rnek, basit bir Node.js API&#8217;sini paketleyen tipik bir Dockerfile&#8217;d\u0131r:<\/p>\n<pre><code># 1. Temel imaj: resmi, hafif Node.js imaj\u0131\nFROM node:20-alpine\n\n# 2. \u00c7al\u0131\u015fma dizinini belirle\nWORKDIR \/app\n\n# 3. Ba\u011f\u0131ml\u0131l\u0131k dosyalar\u0131n\u0131 \u00f6nce kopyala (katman \u00f6nbelle\u011fi i\u00e7in)\nCOPY package*.json .\/\nRUN npm install --production\n\n# 4. Uygulama kodunun geri kalan\u0131n\u0131 kopyala\nCOPY . .\n\n# 5. Konteyner d\u0131\u015f\u0131na a\u00e7\u0131lacak portu belirt\nEXPOSE 3000\n\n# 6. Container ba\u015flad\u0131\u011f\u0131nda \u00e7al\u0131\u015facak komut\nCMD [\"node\", \"server.js\"]<\/code><\/pre>\n<h2>Neden <code>COPY package*.json<\/code> \u00f6nce gelir?<\/h2>\n<p>Docker, her komutu ayr\u0131 bir katman olarak \u00f6nbelle\u011fe al\u0131r. <code>package.json<\/code> de\u011fi\u015fmedi\u011fi s\u00fcrece, <code>npm install<\/code> katman\u0131 tekrar \u00e7al\u0131\u015ft\u0131r\u0131lmaz \u2014 Docker \u00f6nbellekten okur. Kodunuzu de\u011fi\u015ftirdi\u011finizde sadece son katmanlar yeniden in\u015fa edilir. Bu basit s\u0131ralama, build s\u00fcrelerini dakikalardan saniyelere indirebilir.<\/p>\n<h2>\u0130maj\u0131 build etmek ve \u00e7al\u0131\u015ft\u0131rmak<\/h2>\n<pre><code>docker build -t benim-api:1.0 .\ndocker run -d -p 3000:3000 benim-api:1.0<\/code><\/pre>\n<h2>Multi-stage build ile boyutu k\u00fc\u00e7\u00fcltmek<\/h2>\n<p>Derleme (compile) gerektiren dillerde (Go, TypeScript, Java gibi) tek a\u015famal\u0131 bir Dockerfile, build ara\u00e7lar\u0131n\u0131 da nihai imaja ta\u015f\u0131r ve gereksiz yere \u015fi\u015firir. <strong>Multi-stage build<\/strong>, bu sorunu birden fazla <code>FROM<\/code> blo\u011fu kullanarak \u00e7\u00f6zer:<\/p>\n<pre><code># --- build a\u015famas\u0131 ---\nFROM golang:1.22 AS builder\nWORKDIR \/src\nCOPY . .\nRUN go build -o app .\n\n# --- production a\u015famas\u0131 ---\nFROM alpine:3.20\nCOPY --from=builder \/src\/app \/app\nENTRYPOINT [\"\/app\"]<\/code><\/pre>\n<p>\u0130lk a\u015fama Go derleyicisini i\u00e7eren a\u011f\u0131r bir imaj kullan\u0131r; ikinci a\u015fama ise sadece derlenmi\u015f binary&#8217;yi al\u0131p birka\u00e7 megabaytl\u0131k minimal bir Alpine imaj\u0131na kopyalar. Nihai imajda Go derleyicisi, kaynak kod veya build ara\u00e7lar\u0131 <strong>bulunmaz<\/strong> \u2014 sadece \u00e7al\u0131\u015ft\u0131r\u0131labilir dosya kal\u0131r.<\/p>\n<div class=\"callout\">\n  <span class=\"glyph\">\u2713<\/span><\/p>\n<p>\u0130yi pratik: m\u00fcmk\u00fcn oldu\u011funca k\u00fc\u00e7\u00fck taban imajlar (<code>alpine<\/code>, <code>distroless<\/code>) tercih edin, <code>.dockerignore<\/code> dosyas\u0131yla gereksiz dosyalar\u0131 build ba\u011flam\u0131ndan hari\u00e7 tutun ve tek bir Dockerfile i\u00e7inde gereksiz katman say\u0131s\u0131n\u0131 art\u0131rmaktan ka\u00e7\u0131n\u0131n.<\/p>\n<\/div>\n<h2>.dockerignore neden \u00f6nemli?<\/h2>\n<p><code>node_modules<\/code>, <code>.git<\/code> gibi dizinler build context&#8217;e dahil edildi\u011finde hem build s\u00fcresi uzar hem de imaj boyutu gereksiz yere b\u00fcy\u00fcr. Proje k\u00f6k\u00fcne bir <code>.dockerignore<\/code> dosyas\u0131 eklemek, t\u0131pk\u0131 <code>.gitignore<\/code> gibi \u00e7al\u0131\u015f\u0131r:<\/p>\n<pre><code>node_modules\n.git\n*.log\n.env<\/code><\/pre>\n<p>Dockerfile&#8217;\u0131 \u00f6\u011frendikten sonra do\u011fal bir sonraki ad\u0131m, birden fazla servisi (API, veritaban\u0131, cache) birlikte y\u00f6netmek. Bunun i\u00e7in Docker Compose&#8217;u bir sonraki yaz\u0131da ele al\u0131yoruz.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Katman \u00f6nbelle\u011fi, multi-stage build ve .dockerignore gibi pratiklerle kendi Docker imaj\u0131n\u0131z\u0131 nas\u0131l yazaca\u011f\u0131n\u0131z\u0131 \u00f6\u011frenin.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"seviye":[8],"class_list":["post-203","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\/203","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/comments?post=203"}],"version-history":[{"count":1,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":566,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/posts\/203\/revisions\/566"}],"wp:attachment":[{"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/categories?post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/tags?post=203"},{"taxonomy":"seviye","embeddable":true,"href":"https:\/\/konteynerium.com\/index.php\/wp-json\/wp\/v2\/seviye?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}