DEV Community: Docker The latest articles on DEV Community by Docker (@docker). https://dev.to/docker https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F3459%2F42b5911d-1b27-42a6-988a-a45d81aaaf7a.png DEV Community: Docker https://dev.to/docker en Docker Just Made Hardened Images Free for Everyone – Let's Check Them Out! Anil Kumar Moka Mon, 29 Dec 2025 02:03:18 +0000 https://dev.to/docker/docker-just-made-hardened-images-free-for-everyone-lets-check-them-out-499h https://dev.to/docker/docker-just-made-hardened-images-free-for-everyone-lets-check-them-out-499h <p>Hey everyone! If you're like me and spend a lot of time building and deploying containers, you've probably worried about security at some point. Supply chain attacks are no joke these days, and starting with a solid, secure base can make a huge difference. That's why I'm super excited about the recent news from Docker: they've made Docker Hardened Images (DHI) completely free and open source for all developers!Back in May 2025, Docker launched these hardened images as a way to give us minimal, secure, production-ready bases. And just a couple weeks ago (December 17, 2025), they announced that the whole catalog – over 1,000 images and Helm charts – is now free, under Apache 2.0. No subscriptions needed for the basics, no restrictions, no gotchas. This feels like a game-changer for making secure containers the default instead of an afterthought.Let me break it down for you based on the official blog post and docs, and share some practical ways you can start using them today.</p> <h2> What Are Docker Hardened Images? </h2> <p>In simple terms, DHI are container images that Docker maintains with security front and center. They're built on familiar bases like Alpine and Debian, but stripped down to the essentials. No unnecessary shells, compilers, or package managers that could open up attack vectors.The result? <br> Images up to 95% smaller</p> <ul> <li>Way fewer CVEs (they aim for near-zero)</li> <li>Secure defaults, like running as non-root</li> <li>Full transparency with SBOMs (software bill of materials), </li> <li>SLSA Level 3 provenance, and no hidden vulnerabilities</li> </ul> <p>They're inspired by distroless ideas but keep enough tools so you don't have to fight with them in real workflows. And unlike some proprietary options, these are open, compatible with what you're already using, and easy to adopt.</p> <p>There's a free tier for everyone, and an Enterprise version if you need extras like FIPS compliance, customizations, or super-fast patching SLAs.</p> <h2> Why This Matters (And Why Now) </h2> <p>Supply chain attacks are exploding – projected to cost $60 billion this year alone. A lot of that risk comes from bloated base images pulling in stuff your app doesn't need. By starting with a hardened image, you're shrinking that attack surface right from the first docker build.Docker's basically saying: let's make secure-by-default the new normal. And with partnerships from folks like Google, MongoDB, and CNCF, plus companies like Adobe and Qualcomm already using them, it seems like it's catching on fast.</p> <h2> How to Get Started – It's Super Easy </h2> <p>Head over to the catalog on Docker Hub: <a href="proxy.php?url=https://hub.docker.com/hardened-images/catalog" rel="noopener noreferrer">https://hub.docker.com/hardened-images/catalog</a> (you might need to sign in with your Docker ID).Or pull directly from dhi.io. </p> <p>For example, let's try a Python one:bash</p> <p><code>docker pull dhi.io/python:3.13<br> </code><br> Then run something simple:bash</p> <p><code>docker run --rm dhi.io/python:3.13 python -c "print('Hello from a hardened image!')"</code></p> <p>In your Dockerfile, just swap the base:</p> <p><code>FROM dhi.io/python:3.13<br> COPY . /app<br> WORKDIR /app<br> CMD ["python", "app.py"]</code></p> <p>They work great in CI/CD too. And if you're on Kubernetes, check out the open source Hardened Helm Charts.<br> Pro tip from the docs: These images are minimal on purpose, so no shell by default in runtime variants. Use multi-stage builds – compile in a -dev or -sdk tag, then copy to the slim runtime one.</p> <h2> Some Practical Use Cases I Can See </h2> <p>Imagine you're building a Node.js API for a startup. Instead of starting with the regular node image (which has extra stuff), switch to a hardened one. Smaller images mean faster deploys, fewer vulnerabilities to scan, and you sleep better knowing it's locked down.</p> <p>Or say you're deploying MongoDB in prod. Docker has hardened versions of popular MCP servers like Mongo, Grafana, and more. Drop one in, and you've got a secure foundation without rolling your own hardening scripts.</p> <p>For teams in regulated spaces (finance, healthcare), the free versions already give huge wins on CVEs and size. Upgrade to Enterprise if you need FIPS or extended support after upstream EOL.Even for personal projects or learning, why not start secure? It costs nothing extra now.</p> <p>This move by Docker feels huge, putting hardened, transparent images in everyone's hands for free. If you've been putting off tightening up your container security, now's the perfect time to jump in. Go browse the catalog, pull a couple images, and see the difference yourself. Planning to switch any of your projects over? Drop a comment if you've tried them already!</p> docker security devops opensource Docker Hardened Images are Free Mohammad-Ali A'RÂBI Wed, 17 Dec 2025 14:17:35 +0000 https://dev.to/docker/docker-hardened-images-are-free-3cj1 https://dev.to/docker/docker-hardened-images-are-free-3cj1 <p>Docker introduced <strong>Hardened Images</strong> in 2025 as a <strong>secure-by-default base image line</strong>, designed to keep production and development images as close to <strong>zero known CVEs</strong> as realistically possible.</p> <p>As supply chain attacks are on the rise, Docker made the Hardened Images open-source under the Apache 2.0 license to let the community audit and contribute to them.</p> <p>From now on, you can use the hardened images for free in your projects:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight docker"><code><span class="c"># For build stage</span> <span class="k">FROM</span><span class="w"> </span><span class="s">dhi.io/node:24-dev</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="s">build</span> <span class="c"># For production stage</span> <span class="k">FROM</span><span class="s"> dhi.io/node:24</span> </code></pre> </div> <p>To get started, visit <a href="proxy.php?url=https://dhi.io" rel="noopener noreferrer">dhi.io</a>.</p> <h2> How to Pull Hardened Images Locally </h2> <p>To pull the images locally, you need to log into <code>dhi.io</code> first:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker login dhi.io </code></pre> </div> <p>The images are free to use, but you still need to authenticate before pulling them.</p> <p>Use your Docker Hub credentials to login. You can use your personal Docker Hub account and a personal access token (PAT) as the password. No special subscription is required.</p> <p>Then pull the desired image:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker pull dhi.io/node:24 </code></pre> </div> <h2> Check for CVEs </h2> <p>To check for CVEs in the images, you can use Docker Scout:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker scout cves dhi.io/node:24 </code></pre> </div> <p>The image has 8 low-severity CVEs as of December 17th, 2025, as there are no fixed versions available for those packages:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>8 vulnerabilities found in 2 packages CRITICAL 0 HIGH 0 MEDIUM 0 LOW 8 </code></pre> </div> <p>To check with Trivy:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>trivy image <span class="nt">--scanners</span> vuln dhi.io/node:24 </code></pre> </div> <p>Trivy also found 7 low-severity CVEs on one package:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>dhi.io/node:24 (debian 13.2) Total: 7 (UNKNOWN: 0, LOW: 7, MEDIUM: 0, HIGH: 0, CRITICAL: 0) </code></pre> </div> <p>You can still use the Alpine-based hardened images to have a smaller attack surface.</p> <h2> Final Words </h2> <p>There are more than 500 different tags just for the Node.js Hardened Images available on <code>dhi.io</code>, including Alpine-based, Debian-based, dev and runtime, and FIPS and STIG-compliant images. And there are some 100 different repositories for other languages and runtimes, such as Python, Go, Java, .NET, Ruby, and more. And there are Helm charts to deploy DHI images on Kubernetes clusters directly.</p> <p>To explore all available images, visit the <a href="proxy.php?url=https://dhi.io" rel="noopener noreferrer">DHI Catalog</a>.</p> <p>To learn more about Docker and Kubernetes security, check out my book <a href="proxy.php?url=https://buy.dockersecurity.io" rel="noopener noreferrer">Docker and Kubernetes Security</a>, currently 40% off with code <strong>BLACKFOREST25</strong>.</p> docker kubernetes security I Just Published My Book: Docker and Kubernetes Security Mohammad-Ali A'RÂBI Tue, 21 Oct 2025 12:26:34 +0000 https://dev.to/docker/i-just-published-my-book-docker-and-kubernetes-security-17lo https://dev.to/docker/i-just-published-my-book-docker-and-kubernetes-security-17lo <p>The book <em>Docker and Kubernetes Security</em> is finally here, after two years, 170 git commits, and countless hours of writing, editing, and reviewing. It's available on <a href="proxy.php?url=https://DockerSecurity.io" rel="noopener noreferrer">DockerSecurity.io</a>. You can get the eBook, paperback, or a signed copy (that I'll sign and send to you). 🐳🔐</p> <p>So, why did I write this book?</p> <h2> An Unexpected Journey </h2> <p>I became a Docker Captain in March 2023. That probably put me on this publisher's radar. Shortly after that, a major UK publisher reached out to me, asking if I would be interested in writing a book on Docker Security. At first, I was hesitant. Writing a book is a huge commitment, and I wasn't sure if I had enough expertise in Docker Security. The publisher was very persuasive, though, and I eventually agreed to write a proposal.</p> <p>Here is my <a href="proxy.php?url=https://x.com/MohammadAliEN/status/1676867268414676994" rel="noopener noreferrer">monthly tweet</a> about writing a proposal in July 2023:</p> <blockquote> <p>July 2023 goals:</p> <ul> <li>👾 Practice C with Exercism</li> <li>🐳 Submit a Docker talk</li> <li>📝 Write a piece on Telepresence</li> <li>🚘 Pass the driving theory exam</li> <li>📚 Finish the book proposal</li> </ul> </blockquote> <p>Well, I never made it to that DockerCon, because my visa is still pending. But I did finish the proposal!</p> <p>I finished the book, it went through multiple rounds of editing and reviewing, and the technical reviewers gave me a green light by the end of 2024. I was waiting for the final copy-editing and typesetting to be done when I got an email from the publisher in February 2025, named "Intro Call". There was some reorganization happening at the publisher, and they assigned a new team to my book. The intro call was super nice and happy. Then I got an email in March 2025, saying that they are canceling the book project "after a thorough review". I said, "Sure, just verify that the rights are reverted to me". They wrote:</p> <blockquote> <p>Yes, the manuscripts belong to you, and you can find an alternative publisher.</p> </blockquote> <p>I thought, "I have found a new publisher, and that's me!"</p> <h2> Self-Publishing </h2> <p>I set a deadline for myself: October 1st, 2025. I personally love October. It's the month of Oktoberfest, Hacktoberfest, and Halloween. And people are back from Summer mood.</p> <p>When I <a href="proxy.php?url=https://www.linkedin.com/posts/aerabi_docker-kubernetes-activity-7308072260005720065-xSkU?utm_source=share&amp;utm_medium=member_desktop&amp;rcm=ACoAAA4-2tsBY5vUuUj8Cp2-8SacUv_cLm1lUmo" rel="noopener noreferrer">posted on LinkedIn that's publishing in October</a>, I received overwhelming support and encouragement from my network. The post received 5,000 views, 75 reactions, and 20 comments of encouragement.</p> <p>So, I started reaching out to my network for help with self-publishing. Docker Captain Vladimir Mikhalev accepted to be my technical editor. Other Docker Captains accepted to read beta copies and give feedback. I typeset the book using Markdown and LaTeX, and my friend Sima Maherani designed a beautiful cover for it.</p> <p>I started using Amazon's Kindle Direct Publishing (KDP) to publish the eBook and paperback versions. I also set up a website, <a href="proxy.php?url=https://DockerSecurity.io" rel="noopener noreferrer">DockerSecurity.io</a>, to sell signed copies and provide additional resources.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwqffc2xxdyrxlld512o.jpg" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftwqffc2xxdyrxlld512o.jpg" alt="Francesco Ciulla and I in Berlin" width="800" height="1066"></a></p> <p>I took two copies of the book to my talk at WeAreDevelopers in Berlin, where I ran a workshop on Docker Security. There, I ran into Docker Captain Francesco Ciulla, who said he would promote the book when it comes out. I also met Liran Tal, Director of Developer Advocacy at Snyk, who later wrote a foreword for the book.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F173zpv83k9hdwejhkx2u.jpg" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F173zpv83k9hdwejhkx2u.jpg" alt="Liran Tal and I in Berlin" width="800" height="600"></a></p> <h2> The Launch </h2> <p>Finally, the big day arrived: October 1st, 2025. The book was launched on Amazon and <a href="proxy.php?url=https://DockerSecurity.io" rel="noopener noreferrer">DockerSecurity.io</a>. Amazon's KDP network mostly supported English-speaking countries, plus some European countries. Many other countries were not supported, for example, India, although Amazon has a big presence there. So, I set up a signed copy option on <a href="proxy.php?url=https://buy.DockerSecurity.io" rel="noopener noreferrer">buy.DockerSecurity.io</a> to ship books worldwide.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs89l2lh5k0jwr0gbkjfr.jpeg" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs89l2lh5k0jwr0gbkjfr.jpeg" alt="Launch meetup" width="800" height="450"></a></p> <p>Again, after the launch, I received overwhelming support from my network. People started purchasing the book and leaving reviews on Amazon and Goodreads. Docker reshared my launch post on their official LinkedIn page, as well as on Twitter.</p> <p>An Indian Docker Captain reached out and said he wants to give away copies of the book to the winners of a Hackathon he was organizing. It was a challenge to get him the book in time, but we managed to do it. More Captains reached out to congratulate me and offer help with promotion.</p> <p>So far, 3 weeks after the launch, we have had a slow start, but the momentum is building up. The book had sales in Japan, although I did not promote it there. Sales are mostly in Germany, where I'm based. I have received requests from readers in Iran and India who wanted to buy the book but could not find a way to do it. The signed copy is an option, but still expensive, as it's printed in Europe and shipped internationally.</p> <p>I'm currently working with an Indian printer to make the book available in Asia, Africa, and the Middle East. I'm also registering my own ISBN to make the book available in bookstores. They would usually refuse to stock books with Amazon's ISBN.</p> <p>If you are interested in ordering the book, you can find it here: <a href="proxy.php?url=https://buy.DockerSecurity.io" rel="noopener noreferrer">buy.DockerSecurity.io</a>. You can use the following code for a 10 Euros discount: <strong>DEVTO</strong> 🏷️</p> <p>If you want to order on Amazon, you can find the links here: <a href="proxy.php?url=https://DockerSecurity.io" rel="noopener noreferrer">DockerSecurity.io</a>. The website will redirect you to the appropriate Amazon store based on your location.</p> <h2> Conclusion </h2> <p>Writing and self-publishing a technical book is a challenging but rewarding experience. It requires a lot of dedication, perseverance, and support from your network. I'm grateful for everyone who helped me along the way, and I'm excited to see where this journey takes me next.</p> <p>If you want to write a book, you can reach out to me, and I can share the code base I built with Pandoc and LaTeX to help you get started.</p> <p>Meet the heroes who made <em>Docker and Kubernetes Security</em> possible:</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8brzb39b98tsgmm4bz0.jpg" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8brzb39b98tsgmm4bz0.jpg" alt="The book's back cover: Choose your Fighter" width="800" height="987"></a></p> docker books programming writing MCP Horror Stories - Issue 1 Ajeet Singh Raina Fri, 01 Aug 2025 15:23:10 +0000 https://dev.to/docker/mcp-horror-stories-issue-1-2mki https://dev.to/docker/mcp-horror-stories-issue-1-2mki <p>The Model Context Protocol (MCP) is a standardized interface that enables AI agents to interact with external tools, databases, and services. Launched by Anthropic in November 2024, MCP has achieved remarkable adoption, with thousands of MCP server repositories emerging on GitHub. Major technology giants, including Microsoft, OpenAI, Google, and Amazon, have officially integrated MCP support into their platforms, with development tools companies like Block, Replit, Sourcegraph, and Zed also adopting the protocol. </p> <p>Think of MCP as the plumbing that allows ChatGPT, Claude, or any AI agent to read your emails, update databases, manage files, or interact with APIs. Instead of building custom integrations for every tool, developers can use one protocol to connect everything. </p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fat0dermp1mpbkaybk86m.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fat0dermp1mpbkaybk86m.png" alt="Image1" width="800" height="907"></a></p> <p>The Model Context Protocol (MCP) was supposed to be the “USB-C for AI applications” – a universal standard that would let AI agents safely connect to any tool or service. Instead, it’s become a security nightmare that’s putting organizations at risk of data breaches, system compromises, and supply chain attacks.</p> <p>The promise is compelling: Write once, connect everywhere. The reality is terrifying: A protocol designed for convenience, not security.</p> <p>This is issue 1 of a new series – MCP Horror Stories – where we will examine critical security issues and vulnerabilities in the Model Context Protocol (MCP) ecosystem and how Docker MCP Toolkit provides enterprise-grade protection against these threats.</p> <p><a href="proxy.php?url=https://www.docker.com/blog/mcp-security-issues-threatening-ai-infrastructure/" rel="noopener noreferrer">Click here to Read the complete blog</a></p> Docker Deep Dive Workshop at WeAreDevelopers Mohammad-Ali A'RÂBI Wed, 09 Jul 2025 22:30:48 +0000 https://dev.to/docker/docker-deep-dive-workshop-at-wearedevelopers-110c https://dev.to/docker/docker-deep-dive-workshop-at-wearedevelopers-110c <p>Today, I conducted a workshop at WeAreDevelopers World Congress 2025 titled:</p> <blockquote> <p><a href="proxy.php?url=https://app.wearedevelopers.com/events/14/session/35" rel="noopener noreferrer">Docker Deep Dive with a Docker Captain</a></p> </blockquote> <p>The workshop covered the following topics:</p> <ul> <li>Docker Init</li> <li>Docker Bake</li> <li>Docker SBOM</li> <li>SBOM attestations</li> <li>Docker Scout</li> <li>Docker Debug</li> <li>Docker Model Runner</li> <li>Ask Gordon</li> </ul> <p>This article is a step-by-step guide that walks you through the topics, allowing you to recreate the workshop for yourself on demand.</p> <h2> Links </h2> <ul> <li>The GitHub repo: <a href="proxy.php?url=https://github.com/DockerSecurity-io/wap" rel="noopener noreferrer">github.com/DockerSecurity-io/wap</a> </li> <li><a href="proxy.php?url=https://DockerSecurity.io/" rel="noopener noreferrer">Docker and Kubernetes Security Book</a></li> </ul> <h2> Technical Requirements </h2> <ul> <li>Docker Desktop latest version</li> <li>Git</li> <li>A Bash shell (e.g., Git Bash, WSL, or any Linux terminal)</li> </ul> <p>On Windows, you can install Git Bash.</p> <h2> 1. Docker Init </h2> <p><em>Main article: <a href="proxy.php?url=https://dockerhour.com/dockerizing-a-java-24-project-with-docker-init-6f6465758c55" rel="noopener noreferrer">Dockerizing a Java 24 Project with Docker Init</a></em></p> <p><em>Main article: <a href="proxy.php?url=https://javapro.io/2025/07/03/how-to-containerize-a-java-application-securely/" rel="noopener noreferrer">JAVAPRO: How to Containerize a Java Application Securely</a></em></p> <p>Docker Init is a command to initialize a Docker project with a Dockerfile and other necessary files:</p> <ul> <li><code>Dockerfile</code></li> <li><code>compose.yaml</code></li> <li><code>.dockerignore</code></li> <li><code>README.Docker.md</code></li> </ul> <p>The command doesn't use GenAI, so is deterministic, and employs best practices for Dockerfile creation.</p> <p>Docker Init is available on Docker Desktop 4.27 or later and is generally available.</p> <h3> Usage </h3> <p>On the repo, go to the Flask example directory:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">cd </span>flask </code></pre> </div> <p>Then, run the Docker Init command:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker init </code></pre> </div> <p>The command will ask you 4 questions, accept the defaults:</p> <ul> <li>? What application platform does your project use? <strong>Python</strong> </li> <li>? What version of Python do you want to use? <strong>3.13.2</strong> </li> <li>? What port do you want your app to listen on? <strong>8000</strong> </li> <li>? What is the command you use to run your app? <strong>gunicorn 'hello:app' --bind=0.0.0.0:8000</strong> </li> </ul> <p>Then, start Docker Compose with build:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker compose up <span class="nt">--build</span> </code></pre> </div> <p>The application will be available at <a href="proxy.php?url=http://localhost:8000" rel="noopener noreferrer">http://localhost:8000</a>.</p> <h3> Exercises </h3> <ul> <li>1.1. If you want a more tricky example, try Dockerizing a Java 24 application using Docker Init. You can follow the instructions in the <a href="proxy.php?url=https://javapro.io/2025/07/03/how-to-containerize-a-java-application-securely/" rel="noopener noreferrer">JAVAPRO article</a> that I published last week.</li> <li>1.2. Compare the Dockerfile created for the Java application with the one created for the Python application. What are the differences?</li> </ul> <h2> 2. Docker Bake </h2> <p><em>Requirement: This step requires the Docker Init step to be completed first.</em></p> <p>Docker Bake is to Docker Build, what Docker Compose is to Docker Run. It allows you to build multiple images at once, using a single command.</p> <p>Docker Bake is available on Docker CE and Docker Desktop, and is generally available.</p> <h3> Usage </h3> <p>In the repo, go to the Flask example directory:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">cd </span>flask </code></pre> </div> <p>Then, try to build the image using Docker Bake:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker buildx bake </code></pre> </div> <p>The command will build the image using the <code>docker-bake.hcl</code> file in the current directory. At the end, there is a Docker Desktop link shown in the output, with which you can see the build progress in the Docker Desktop UI.</p> <p>Also, there are probably some warnings about the Dockerfile.</p> <h3> Exercises </h3> <ul> <li>2.1. Try to fix the warnings in the Dockerfile.</li> <li>2.2. By changing the <code>docker-bake.hcl</code> file, try building for multiple platforms, e.g., <code>linux/amd64</code> and <code>linux/arm64</code>. </li> <li>2.3. Try to build the image with a different Python version, e.g., <code>3.13.1</code> (the Python version is defined in the Dockerfile as a build argument, <code>PYTHON_VERSION</code>).</li> </ul> <h2> 3. Docker SBOM </h2> <p><em>Requirement: This step requires the Docker Init step to be completed first.</em></p> <p>In Docker Init step, we built an image with tag <code>flask-server:latest</code> when running <code>docker compose up --build</code>. Let's check the SBOM for this image.</p> <p>Docker SBOM is integrated into Docker Desktop, but is also available for Docker CE as a CLI plugin that you need to install separately.</p> <h3> Usage </h3> <p>To check the SBOM for the image, run:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker sbom flask-server:latest </code></pre> </div> <p>The output will show the SBOM in a table format. Try to export it to a SPDX file:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker sbom <span class="nt">--format</span> spdx-json flask-server:latest <span class="o">&gt;</span> sbom.spdx.json </code></pre> </div> <p>If you investigate the file, you will see that it contains a list of all the packages used in the image, their versions, and the licenses. It's especially useful for compliance and security purposes.</p> <p>A more interesting example will be a C++ application.</p> <p>Go to the C++ example directory:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">cd </span>cpp </code></pre> </div> <p>Then, build the image:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker build <span class="nt">-t</span> cpp-hello <span class="nb">.</span> </code></pre> </div> <p>Now, check the SBOM for the image:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker sbom cpp-hello </code></pre> </div> <p>It will say there are no packages in the image, because the image is built from a <code>FROM scratch</code> base image. But, in the build stage, we installed many packages, and a vulnerability in those packages can affect the final image.</p> <p>We'll get back to this later.</p> <h3> Exercises </h3> <ul> <li>3.1. Try to create a Docker Bake file for the C++ example, and build the image using Docker Bake.</li> <li>3.2. Use <code>docker sbom --help</code> to check available formats for the SBOM output.</li> </ul> <h2> 4. SBOM Attestations </h2> <p><em>Requirement: This step requires the Docker SBOM step to be completed first.</em></p> <p><em>Main article: <a href="proxy.php?url=https://docs.docker.com/guides/cpp/security/" rel="noopener noreferrer">DockerDocs: Supply-Chain Security for C++ Images</a></em></p> <p>SBOM attestations are SBOMs generated for Docker images and uploaded with them to the registry.</p> <h3> Usage </h3> <p>SBOM attestations are generated during the build and pushed to the registry automatically:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker buildx build <span class="nt">--sbom</span><span class="o">=</span><span class="nb">true</span> <span class="nt">--push</span> <span class="nt">-t</span> aerabi/cpp-hello <span class="nb">.</span> </code></pre> </div> <p>Now, let's check the CVEs with Docker Scout (we will cover it in the next section):<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker scout cves aerabi/cpp-hello </code></pre> </div> <p>It will say:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>SBOM obtained from attestation, 0 packages found </code></pre> </div> <p>The SBOM has no packages, because we built the image from a <code>FROM scratch</code> base image, and the build stage packages are not included in the SBOM. We can fix this by including the build stage packages in the SBOM.</p> <p>To do that, we need to add the following line to the beginning of the <code>Dockerfile</code>:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight docker"><code><span class="k">ARG</span><span class="s"> BUILDKIT_SBOM_SCAN_STAGE=true</span> </code></pre> </div> <p>This line goes before the <code>FROM</code> line, and it tells Docker to include the build stage packages in the SBOM.</p> <p>Now, rebuild the image with the new Dockerfile:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker buildx build <span class="nt">--sbom</span><span class="o">=</span><span class="nb">true</span> <span class="nt">--push</span> <span class="nt">-t</span> aerabi/cpp-hello:with-build-stage <span class="nb">.</span> </code></pre> </div> <p>Now, check the SBOM attestations for the image again:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker scout cves aerabi/cpp-hello:with-build-stage </code></pre> </div> <p>It will say:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>SBOM of image already cached, 208 packages indexed </code></pre> </div> <h3> Exercises </h3> <ul> <li>4.1. Here, the build command was super long. Try to create a Docker Bake file for the C++ example, and build the image using Docker Bake with SBOM attestations.</li> </ul> <h2> 5. Docker Scout </h2> <p><em>Requirement: This step requires the SBOM Attestations step to be completed first.</em></p> <p>Docker Scout is a tool to analyze Docker images and check for vulnerabilities, misconfigurations, and other issues. It uses the SBOM attestations, when available, to provide more accurate results.</p> <p>Docker Scout is available on Docker Desktop, and as a CLI plugin for Docker CE.</p> <h3> Usage </h3> <p>To check the vulnerabilities in the image, run:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker scout cves aerabi/cpp-hello:with-build-stage </code></pre> </div> <p>You can also check the vulnerabilities in the image using the Docker Desktop UI. Just go to the "Images" tab, select the image, and click on "Scout".</p> <p>There are also recommendations for the image, which you can check by running:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker scout recommendations flask-server </code></pre> </div> <h3> Exercises </h3> <ul> <li>5.1. Try to fix the vulnerabilities in the Flask image using the recommendations from Docker Scout.</li> </ul> <h2> 6. Docker Debug </h2> <p><em>Requirement: This step requires the Docker SBOM step to be completed first.</em></p> <p>Docker Debug is a tool to debug Docker images and containers. It allows you to run a container with a debug shell, and inspect the image and the container.</p> <p>Docker Debug is a paid feature available on Docker Desktop.</p> <h3> Usage </h3> <p>Docker Debug can be used to investigate images or containers, when <code>docker exec</code> is not enough. For example, you can use it to inspect a scratch image:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker debug aerabi/cpp-hello:with-build-stage </code></pre> </div> <h3> Exercises </h3> <ul> <li>6.1. Use Docker Debug to inspect the C++ image.</li> <li>6.2. Use Docker Debug to inspect the Flask image.</li> <li>6.3. Run the Flask image and inspect it with Docker Debug.</li> <li>6.4. Install a tool like Vim using Docker Debug. The tools persist between different inspections. Try to inspect another container and check if the tool is still there.</li> </ul> <h2> 7. Docker Model Runner </h2> <p><em>Main article: <a href="proxy.php?url=https://dev.to/docker/run-genai-models-locally-with-docker-model-runner-5elb">Run GenAI Models Locally with Docker Model Runner</a></em></p> <p>Docker Model Runner is a tool to run GenAI models locally using Docker. The feature is still in beta, but is available on Linux, macOS, and Windows.</p> <ul> <li>Linux: Docker CE</li> <li>macOS: Docker Desktop 4.40 or later</li> <li>Windows: Docker Desktop 4.41 or later</li> </ul> <p>On Docker CE, you need to install the Docker Model Runner plugin:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">sudo </span>apt-get <span class="nb">install </span>docker-model-plugin </code></pre> </div> <h3> Usage </h3> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker model run ai/gemma3 </code></pre> </div> <p>To use Docker Model Runner for developing GenAI applications, you can pull the models, and they will become available locally. Whenever an application needs to use a model, it can use the local models.</p> <p>And example application is available here:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>git clone https://github.com/aerabi/genai-app-demo <span class="nb">cd </span>genai-app-demo </code></pre> </div> <p>Edit the file <code>backend.env</code> and make it match the following content:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>BASE_URL: http://model-runner.docker.internal/engines/llama.cpp/v1/ MODEL: ai/gemma3 API_KEY: ${API_KEY:-dockermodelrunner} </code></pre> </div> <p>Then, run the application:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>docker compose up <span class="nt">-d</span> </code></pre> </div> <h3> Exercises </h3> <ul> <li>7.1. Docker Compose now supports the <code>model</code> service type (<a href="proxy.php?url=https://docs.docker.com/ai/compose/models-and-compose/" rel="noopener noreferrer">learn more</a>). Try to adapt the Compose file in the repo to declare the model as a service.</li> </ul> docker From Zero to Kubernetes: A Beginner's Guide to Orchestrating Docker Containers Karan Verma Sat, 31 May 2025 12:30:28 +0000 https://dev.to/docker/from-zero-to-kubernetes-a-beginners-guide-to-orchestrating-docker-containers-leg https://dev.to/docker/from-zero-to-kubernetes-a-beginners-guide-to-orchestrating-docker-containers-leg <p><strong>Introduction</strong></p> <p>If you've ever built or deployed applications using Docker, you've likely hit a point where running containers on your laptop just isn’t enough. You need scaling, automation, recovery, and networking across machines. Enter Kubernetes, the container orchestrator trusted by startups and tech giants alike. In this beginner-friendly guide, we’ll walk you through what Kubernetes is, why it matters, and how Docker developers can start leveraging its power.</p> <p><strong>What is Kubernetes?</strong></p> <p>Kubernetes (also called K8s) is an open-source platform that automates deploying, scaling, and managing containerized applications. While Docker helps package your app into a container, Kubernetes helps run and scale it across many machines.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frwp2o04bgatzrrim2j8h.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frwp2o04bgatzrrim2j8h.png" alt="arch" width="800" height="533"></a><br> Kubernetes architecture explained: The Control Plane manages the cluster while Nodes run Pods, which host your Docker containers.</p> <p><strong>Why Use Kubernetes?</strong></p> <p><strong>- Self-Healing:</strong> Restarts failed containers automatically.<br> <strong>- Scalability:</strong> Scale apps up or down automatically with a single command.<br> <strong>- Declarative Management:</strong> Define your infrastructure and app needs using YAML files.<br> <strong>- Portability:</strong> Run anywhere from your laptop with Minikube to cloud providers like AWS, GCP, or Azure.</p> <p><strong>How Kubernetes Works (for Docker Devs)</strong></p> <p>Kubernetes works on a cluster model. A cluster has:</p> <p><strong>- Master Node (Control Plane):</strong> Handles scheduling, scaling, and communication.<br> <strong>- Worker Nodes:</strong> Run your Docker containers inside Pods.</p> <p><strong>Pods and Deployments</strong></p> <p>A Pod is the smallest deployable unit in Kubernetes. It wraps your container(s) and runs on a node. You usually don’t run Pods directly, you use Deployments to manage them.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq6as56oqoss71o68qqcs.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq6as56oqoss71o68qqcs.png" alt="Pod &amp; Deployment Flow" width="800" height="800"></a></p> <p><strong>Exposing Your App with Services</strong></p> <p>Pods can come and go. You need a stable way to expose them; that’s where Services come in. A Service routes traffic to the right Pods and load-balances across them.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fss43jo4u9cb4edxeslyg.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fss43jo4u9cb4edxeslyg.png" alt="Image description" width="800" height="800"></a><br> Kubernetes Service: Traffic from users is routed through a Service to reach the right Pods, ensuring balanced and reliable access to your app.</p> <p><strong>Step-by-Step: Try It Yourself with Minikube</strong></p> <p>Let’s get hands-on!</p> <p><strong>1. Install Minikube &amp; kubectl</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>brew install minikube minikube start kubectl get nodes </code></pre> </div> <p><strong>2. Create a Deployment YAML</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>apiVersion: apps/v1 kind: Deployment metadata: name: my-web-app spec: replicas: 2 selector: matchLabels: app: web template: metadata: labels: app: web spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 </code></pre> </div> <p><strong>3. Deploy it to Kubernetes</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>kubectl apply -f deployment.yaml kubectl get pods </code></pre> </div> <p><strong>4. Expose Your Deployment as a Service</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>kubectl expose deployment my-web-app --type=NodePort --port=80 </code></pre> </div> <p><strong>5. Access Your App</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>minikube service my-web-app </code></pre> </div> <p><strong>Bonus: Access a Pod Directly (Port Forwarding)</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>kubectl port-forward pod/my-web-app-xxxx 8080:80 </code></pre> </div> <p><strong>📚 Further Reading</strong></p> <p>Here are some trusted, beginner-friendly resources to deepen your Kubernetes knowledge, especially curated for developers coming from Docker:</p> <ul> <li><p><a href="proxy.php?url=https://kubernetes.io/docs/" rel="noopener noreferrer">Kubernetes Official Documentation</a>: The canonical source for Kubernetes knowledge, straight from the maintainers.</p></li> <li><p><a href="proxy.php?url=https://docs.docker.com/get-started/orchestration/" rel="noopener noreferrer">Docker + Kubernetes (Docker Docs)</a>: Docker’s own guide on moving from Docker CLI to Kubernetes orchestration. </p></li> <li><p><a href="proxy.php?url=https://minikube.sigs.k8s.io/docs/start/" rel="noopener noreferrer">Minikube Official Docs</a>: Run Kubernetes locally in minutes, perfect for testing and dev environments.</p></li> <li><p><a href="proxy.php?url=https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="noopener noreferrer">kubectl Cheat Sheet</a>: Bookmark this as your go-to for common Kubernetes CLI commands.</p></li> <li><p><a href="proxy.php?url=https://docs.digitalocean.com/products/kubernetes/getting-started/deploy-image-to-cluster/" rel="noopener noreferrer">Build and Deploy Your First Image on DigitalOcean Kubernetes</a>: A hands-on tutorial that ties together Docker image creation and Kubernetes deployment.</p></li> <li><p><a href="proxy.php?url=https://www.youtube.com/watch?v=X48VuDVv0do" rel="noopener noreferrer">Kubernetes for Beginners (YouTube - TechWorld with Nana)</a>: A visual, practical walkthrough of key Kubernetes concepts is great for Docker users.</p></li> </ul> <p><strong>Conclusion</strong></p> <p>Kubernetes might seem complex at first, but if you’re already familiar with Docker, you’re well on your way to mastering it. In this guide, you took important first steps by deploying your app, scaling it, and exposing it with a service, all using tools on your own machine. With a bit of practice and curiosity, you’ll soon unlock the full power of Kubernetes to manage containers at scale, whether locally or in the cloud. </p> <p><strong>Keep experimenting, and enjoy the journey from zero to Kubernetes pro!</strong>🚀</p> kubernetes docker devops cloudnative Docker MCP Catalog & Toolkit: Building Smarter AI Agents with Ease Karan Verma Tue, 20 May 2025 11:43:38 +0000 https://dev.to/docker/docker-mcp-catalog-toolkit-building-smarter-ai-agents-with-ease-408c https://dev.to/docker/docker-mcp-catalog-toolkit-building-smarter-ai-agents-with-ease-408c <p><strong>Introduction: What Is Docker MCP and Why It Matters</strong></p> <p>The rise of agent-based AI applications, powered by ChatGPT, Claude, and custom LLMs, has created a demand for modular, secure, and standardized integrations with real-world tools. Docker’s Model Context Protocol (MCP), along with its Catalog and Toolkit, addresses this need.</p> <p>Docker is positioning itself not just as a container platform but as the infrastructure backbone for intelligent agents. In this post, we’ll explore the MCP architecture, Catalog, and Toolkit, and demonstrate how to build your own MCP server.</p> <h2> Section 1: Understanding MCP: The Model Context Protocol </h2> <p><strong>What it is:</strong></p> <ul> <li>MCP is an <strong>open protocol</strong> that allows AI clients (like agents) to call real-world services securely and predictably.</li> <li>It's designed for tool interoperability, secure credential management (handling API keys and tokens), and container-based execution.</li> </ul> <p><strong>Why it matters:</strong></p> <ul> <li>Without standards like MCP, agents rely on brittle APIs or unsafe plugins.</li> <li>Docker provides a secure, isolated runtime to host these services in containers.</li> </ul> <p><strong>Visual overview:</strong></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnl9fzxlbty6djtfhhuzn.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnl9fzxlbty6djtfhhuzn.png" alt="MCP Arch Diagram" width="800" height="533"></a></p> <p><em>How an AI client communicates with containerized services via MCP</em></p> <h2> Section 2: MCP Catalog: Prebuilt, Secure MCP Servers </h2> <p><strong>What it includes:</strong></p> <p>A growing library of 100+ Docker-verified MCP servers, including:</p> <ul> <li>Stripe</li> <li>LangChain</li> <li>Elastic</li> <li>Pinecone</li> <li>Hugging Face</li> </ul> <p><strong>Key features:</strong></p> <p>Each MCP server runs inside a container and includes:</p> <ul> <li>OpenAPI spec</li> <li>Secure default config</li> <li>Docker Desktop integration</li> </ul> <p><strong>Why developers care:</strong></p> <ul> <li>Plug-and-play tools for AI agents.</li> <li>Consistent dev experience across services.</li> </ul> <p><strong>Visual overview:</strong></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr1awaatmw44r57fm2as3.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr1awaatmw44r57fm2as3.png" alt="MCP Catalog Diagram" width="800" height="533"></a></p> <p><em>MCP Catalog integration with Docker Desktop</em></p> <h2> Section 3: MCP Toolkit: Build Your Own Secure MCP Server </h2> <p><strong>Toolkit CLI Features:</strong></p> <ul> <li> <code>mcp init</code> → Scaffolds new MCP server</li> <li> <code>mcp run</code> → Runs local dev version</li> <li> <code>mcp deploy</code> → Deploy to Docker Desktop</li> </ul> <p><strong>Security features:</strong></p> <ul> <li>Container isolation</li> <li>OAuth support for credentials</li> <li>Optional rate limiting and tracing</li> </ul> <p><strong>Demo walkthrough:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>npm install -g @docker/mcp-toolkit mcp init my-weather-api cd my-weather-api mcp run </code></pre> </div> <p><strong>Visual walkthrough:</strong></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpflyy3al2z9h1nxzhw03.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpflyy3al2z9h1nxzhw03.png" alt="MCP Toolkit Diagram" width="800" height="533"></a></p> <p><em>MCP Toolkit Workflow: From CLI to Container</em></p> <h2> Section 4: Connecting MCP Servers to AI Clients </h2> <p><strong>Supported clients:</strong></p> <ul> <li>Claude (Anthropic)</li> <li>GPT Agents (OpenAI)</li> <li>Docker AI (beta)</li> <li>VS Code Extensions</li> </ul> <p><strong>How it works:</strong></p> <ul> <li>Agents call <code>/invoke</code> endpoint defined in MCP spec.</li> <li>Secure token exchange handles identity.</li> <li>Response returned to model for reasoning/action.</li> </ul> <p><strong>Use case example:</strong></p> <p><em>Claude uses a Docker MCP server to call a Stripe payment processing container during an e-commerce interaction.</em></p> <p><strong>Visual flow:</strong></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqht7pop4qx9u0lakaito.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqht7pop4qx9u0lakaito.png" alt="Agent-to-API via Docker MCP" width="800" height="533"></a></p> <p><em>Shows how Claude securely calls a Stripe service via Docker MCP.</em></p> <h2> Section 5: Best Practices for MCP Server Developers </h2> <p><strong>Security:</strong></p> <ul> <li>Never use root containers</li> <li>Use <code>docker scan</code> and <code>trivy</code> for image vulnerability scanning</li> <li>Store secrets with Docker's secret manager (or Vault)</li> </ul> <p><strong>Performance:</strong></p> <ul> <li>Keep containers lightweight (use Alpine or Distroless)</li> <li>Use streaming responses for LLM interaction</li> </ul> <p><strong>Testing tips:</strong></p> <ul> <li>Use <code>Postman</code> + <code>curl</code> to test <code>/invoke</code> endpoint</li> <li>Lint OpenAPI specs with <code>swagger-cli</code> </li> </ul> <h2> Section 6: The Future of MCP: What Comes Next? </h2> <p><strong>Predictions:</strong></p> <ul> <li>Docker AI Dashboard integration</li> <li>MCP orchestration (multiple services per agent)</li> <li>AI-native DevOps (agents building infra with MCP servers)</li> </ul> <p><strong>Opportunities for devs:</strong></p> <ul> <li>Contribute to open MCP servers</li> <li>Submit to Docker Catalog</li> <li>Build agent tools for internal or public use</li> </ul> <p><strong>Closing Thoughts</strong></p> <p>Docker’s MCP Catalog and Toolkit are still in beta, but the path forward is clear: AI apps need real-world tool access, and Docker is building a secure, open ecosystem to power it.</p> <p>Whether you’re building agent frameworks or just experimenting with tool-using LLMs, now’s the perfect time to get involved.</p> <p>Got ideas for MCP servers you want to see? Or thinking about contributing your own? I’d love to hear from you! 😊</p> dockermcp aiagents containersecurity devopsai From Beginner to Pro: Docker + Terraform for Scalable AI Agents Karan Verma Sat, 03 May 2025 10:49:32 +0000 https://dev.to/docker/from-beginner-to-pro-deploying-scalable-ai-workloads-with-docker-terraform-41f2 https://dev.to/docker/from-beginner-to-pro-deploying-scalable-ai-workloads-with-docker-terraform-41f2 <p><strong>Introduction</strong></p> <p>As AI and machine learning workloads grow more complex, developers and DevOps engineers are looking for reliable, reproducible, and scalable ways to deploy them. While tools like Docker and Terraform are widely known, many developers haven’t yet fully unlocked their combined potential, especially when it comes to deploying AI agents or LLMs across cloud or hybrid environments.</p> <p>This guide walks you through the journey from Docker and Terraform basics to building scalable infrastructure for modern AI/ML systems.</p> <p>Whether you’re a beginner trying to get your first container up and running or an expert deploying multi-agent LLM setups with GPU-backed infrastructure, this article is for you.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkfojs9wd8srqueomzc2m.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkfojs9wd8srqueomzc2m.png" alt="docker terraform" width="800" height="800"></a></p> <p><strong>Docker 101: Containerizing Your First AI Model</strong></p> <p>Let’s start with Docker. Containers make it easier to package and ship your applications. Here’s a quick example of containerizing a PyTorch-based inference model.</p> <p><strong>Dockerfile:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>FROM python:3.9-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . CMD ["python", "inference.py"] </code></pre> </div> <p><strong>Build &amp; Run:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>docker build -t ai-agent . docker run -p 5000:5000 ai-agent </code></pre> </div> <p>You now have a reproducible and portable AI model running in a container!</p> <p><strong>Terraform 101: Your Infrastructure as Code</strong></p> <p>Now let’s set up the infrastructure to run this container in the cloud using Terraform.</p> <p><strong>Basic Terraform Script:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>provider "aws" { region = "us-east-1" } resource "aws_instance" "agent" { ami = "ami-0abcdef1234567890" # Choose a GPU-compatible AMI instance_type = "g4dn.xlarge" provisioner "remote-exec" { inline = [ "sudo docker run -d -p 5000:5000 ai-agent" ] } } </code></pre> </div> <p><strong>Deploy:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>terraform init terraform apply </code></pre> </div> <p>Boom your container is live on an EC2 instance!</p> <p><strong>Integrating Docker + Terraform: Scalable AI Agent Setup</strong></p> <p>Now, we combine both tools to:</p> <ul> <li>Auto-provision compute with Terraform</li> <li>Pull and run your Docker images automatically</li> <li>Scale agents dynamically by changing Terraform variables</li> </ul> <p>Example:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>variable "agent_count" { default = 3 } resource "aws_instance" "agent" { count = var.agent_count ami = "ami-0abc123456" instance_type = "g4dn.xlarge" ... } </code></pre> </div> <p>This lets you spin up multiple Dockerized AI agents across your cloud fleet—perfect for inference APIs or retrieval-augmented generation (RAG) systems.</p> <p><strong>Advanced Use Case: AI Agents with Multi-GPU, CI/CD &amp; Terraform</strong></p> <p><strong>Imagine this setup:</strong></p> <ul> <li>Each agent runs an OpenAI-compatible LLM locally (e.g., Mistral, Ollama, LLaMA.cpp)</li> <li>Terraform provisions GPU instances and networking</li> <li>Docker builds include prompt routers and memory systems</li> <li>GitHub Actions auto-triggers Terraform for deployments</li> </ul> <p><strong>Benefits:</strong></p> <ul> <li>Reproducibility across dev, staging, and prod</li> <li>Cost savings via spot instances</li> <li>Seamless rollback via Terraform state</li> </ul> <p>This is modern MLOps, containerized.</p> <p><strong>☁️ Hybrid Multi-Cloud AI with Docker + Terraform</strong></p> <p>You can even expand this setup to support:</p> <ul> <li>Azure or GCP compute targets</li> <li>Multi-region failover</li> <li>Local LLM agents in Docker Swarm clusters (home lab, edge)</li> </ul> <p><strong>Pro Tip:</strong> Use Terraform Cloud or Atlantis for remote state and team workflows.</p> <p><strong>Visual Overview: How Docker and Terraform Work Together to Deploy AI Agents</strong></p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfnbt92fso865h46di3p.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbfnbt92fso865h46di3p.png" alt="arch docker and terraform" width="800" height="533"></a></p> <p>This diagram maps the full lifecycle from writing infrastructure-as-code, containerizing models, and deploying everything automatically.</p> <p><strong>Simulated Real-World Project: Structure, README &amp; CLI</strong></p> <p>This structure outlines a robust setup designed for deploying and testing Docker + Terraform AI agents in hybrid cloud environments. It’s a scalable, reliable framework that can be leveraged for complex AI deployments.</p> <p><strong>📁 Project Structure</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>. ├── Dockerfile ├── terraform/ │ ├── main.tf │ ├── variables.tf │ └── outputs.tf ├── cloud-init/ │ └── init.sh ├── ai-model/ │ ├── inference.py │ └── requirements.txt └── README.md </code></pre> </div> <p><strong>Sample README.md (Private/Internal Repo Summary)</strong></p> <p><strong>Title:</strong> Scalable AI Agent Deployment with Docker &amp; Terraform</p> <p>This project sets up a fully Dockerized AI inference agent that is deployed via Terraform on GPU-enabled EC2 instances. It demonstrates:</p> <ul> <li>Docker container for model inference (PyTorch/Transformers)</li> <li>Terraform to provision compute infra + networking</li> <li>Cloud-init for auto-starting containers post-launch</li> <li>Multi-agent scaling logic with variable interpolation</li> </ul> <p><strong>Basic Usage:</strong></p> <p><code>terraform init<br> terraform apply</code></p> <p><strong>Run Docker Locally:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>docker build -t ai-agent . docker run -p 5000:5000 ai-agent </code></pre> </div> <p><strong>CLI Output Snapshot</strong></p> <p>Terraform:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>&gt; terraform apply Apply complete! Resources: - aws_instance.agent[0] - aws_security_group.main Public IP: 34.201.12.77 </code></pre> </div> <p>Docker:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>&gt; docker ps CONTAINER ID IMAGE COMMAND STATUS PORTS ae34c2f1c11b ai-agent "python inference.py" Up 2 mins 5000/tcp </code></pre> </div> <p>⚙️ Note: This setup has been tested with both local GPUs and AWS EC2 g4dn instances. The Docker + Terraform pipeline helped me cut down deployment effort by over 60% and simplified environment consistency across dev and test runs.</p> <p><strong>Simulated Real-World Project: Structure, README &amp; CLI</strong></p> <p>This structure outlines a robust setup designed for deploying and testing Docker + Terraform AI agents in hybrid cloud environments. It’s a scalable, reliable framework that can be leveraged for complex AI deployments.</p> <p>For more information on Docker, you can refer to the <a href="proxy.php?url=https://docs.docker.com/" rel="noopener noreferrer">official Docker documentation</a> and explore relevant open-source projects on <a href="proxy.php?url=https://github.com/docker" rel="noopener noreferrer">Docker's GitHub</a>. Additionally, for Terraform-related resources, check out the <a href="proxy.php?url=https://www.terraform.io/docs/" rel="noopener noreferrer">official Terraform documentation</a> and <a href="proxy.php?url=https://github.com/hashicorp/terraform" rel="noopener noreferrer">Terraform GitHub</a>.</p> <p><strong>Final Takeaways</strong></p> <ul> <li>✅ Docker simplifies packaging AI/ML models</li> <li>✅ Terraform provisions scalable infrastructure in minutes</li> <li>✅ Together, they form a powerful pattern for reliable AI deployment</li> </ul> <p>Whether you’re running LLMs locally, deploying agents in the cloud, or scaling across multi-cloud environments, this stack is your launchpad.</p> <p>👋 Call to Action</p> <p>If this guide helped you, share it with your team or community!</p> <p>Thanks for reading. Happy hacking and may your containers always build clean! 🚀</p> docker terraform aideployment mlops From Zero to GenAI Cluster: Scalable Local LLMs with Docker, Kubernetes, and GPU Scheduling Karan Verma Sat, 03 May 2025 08:11:44 +0000 https://dev.to/docker/from-zero-to-genai-cluster-scalable-local-llms-with-docker-kubernetes-and-gpu-scheduling-47on https://dev.to/docker/from-zero-to-genai-cluster-scalable-local-llms-with-docker-kubernetes-and-gpu-scheduling-47on <p>A practical guide to deploying fast, private, and production-ready large language models with vLLM, Ollama, and Kubernetes-native orchestration. Build your own scalable GenAI cluster with Docker, Kubernetes, and GPU scheduling for a fully private, production-ready LLM setup.</p> <p><strong>Prerequisites</strong></p> <p>Before we begin, ensure your system meets the following requirements:</p> <ul> <li>A Kubernetes cluster with <strong>GPU-enabled nodes</strong> (e.g., via GKE, AKS, or bare-metal)</li> <li>The <strong>NVIDIA device plugin</strong> installed on the cluster</li> <li>Helm CLI installed and configured</li> <li>Docker CLI and access to a GPU-compatible runtime (e.g., <code>nvidia-docker2</code>)</li> </ul> <p><strong>Introduction</strong></p> <p>Local LLMs are no longer a research luxury, they're a production need. But deploying them at scale, with GPU access, container orchestration, and real-time monitoring? That’s still murky territory for many.</p> <p>In this article, I’ll walk you through how I built a fully operational GenAI cluster using Docker, Kubernetes, and GPU scheduling. It serves powerful language models like vLLM, Ollama, or HuggingFace TGI. We’ll make it observable with Prometheus and Grafana, and ready to scale when the real load hits.</p> <p>This isn’t just another tutorial. It’s a battle-tested, experience-backed <strong>blueprint for real-world AI infrastructure</strong>, written for developers and DevOps engineers pushing the boundaries of what GenAI can do.</p> <p><strong>Why Local/Private LLMs Matter</strong></p> <p>Many teams today are realizing that hosted APIs like OpenAI and Anthropic, while convenient, come with serious trade-offs:</p> <ul> <li> <strong>Cost grows fast</strong> when usage scales</li> <li> <strong>Sensitive data</strong> can't always be sent to third-party clouds</li> <li> <strong>Customization</strong> is limited to what the API provider allows</li> <li> <strong>Latency</strong> becomes a bottleneck in low-connectivity environments</li> </ul> <p>Self-hosting LLMs means freedom, control, and flexibility. But only if you know how to do it <strong>right</strong>.</p> <p><strong>What We'll Build</strong></p> <p>We’ll deploy a production-grade Kubernetes cluster featuring:</p> <ul> <li> <strong>vLLM / Ollama / TGI</strong> model server containers</li> <li><strong>GPU scheduling and node affinity</strong></li> <li> <strong>Ingress with HTTPS</strong> via NGINX</li> <li> <strong>Autoscaling</strong> using HPA or KEDA</li> <li> <strong>Prometheus + Grafana</strong> for real-time insights</li> <li>Declarative infrastructure using Helm or plain YAML</li> </ul> <p><strong>Architecture Overview</strong></p> <p>Figure: High-level architecture of a scalable GenAI Cluster using Docker, Kubernetes, and GPU scheduling.</p> <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnip2b5o2rc75447cwwt0.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnip2b5o2rc75447cwwt0.png" alt="Arch Docker" width="800" height="1200"></a></p> <p>This modular, observable cluster gives you full control over your LLM infrastructure, without vendor lock-in.</p> <p><strong>Step 1: Dockerizing the Model Server</strong></p> <p>Let’s start small: a single Docker container that wraps a model server like vLLM.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code># Dockerfile.vllm FROM nvidia/cuda:12.2.0-base-ubuntu20.04 RUN apt update &amp;&amp; apt install -y git python3 python3-pip RUN pip install vllm torch transformers WORKDIR /app COPY start.sh ./ CMD ["bash", "start.sh"] </code></pre> </div> <p><strong>start.sh:</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>#!/bin/bash python3 -m vllm.entrypoints.openai.api_server --model facebook/opt-1.3b --port 8000 </code></pre> </div> <p>Then, build your container:</p> <p><code>docker build -f Dockerfile.vllm -t vllm-server:v0.1 .</code></p> <p>You can also use Ollama if you prefer pre-packaged models and a lower barrier to entry. vLLM is recommended for higher throughput and OpenAI-compatible APIs.</p> <p>This is your first step toward building a modular, GPU-ready inference system.</p> <p><strong>Step 2: Kubernetes Deployment with GPU Scheduling</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>apiVersion: apps/v1 kind: Deployment metadata: name: vllm-deployment spec: replicas: 1 selector: matchLabels: app: vllm template: metadata: labels: app: vllm spec: containers: - name: vllm image: vllm-server:v0.1 resources: limits: nvidia.com/gpu: 1 ports: - containerPort: 8000 nodeSelector: kubernetes.io/role: gpu tolerations: - key: "nvidia.com/gpu" operator: "Exists" effect: "NoSchedule" </code></pre> </div> <p>And here’s the corresponding <strong>Service</strong> definition:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>apiVersion: v1 kind: Service metadata: name: vllm-service spec: selector: app: vllm ports: - protocol: TCP port: 8000 targetPort: 8000 </code></pre> </div> <p>This exposes your model server inside the cluster.</p> <p><strong>Step 3: Ingress and Load Balancing</strong></p> <p>Install NGINX Ingress Controller:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm install nginx ingress-nginx/ingress-nginx </code></pre> </div> <p>Then configure ingress:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: vllm-ingress spec: rules: - host: vllm.local http: paths: - path: / pathType: Prefix backend: service: name: vllm-service port: number: 8000 </code></pre> </div> <p>Update your DNS or <code>/etc/hosts</code> to route <code>vllm.local</code> to your cluster.</p> <p><strong>Step 4: Autoscaling with KEDA (Optional)</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>helm repo add kedacore https://kedacore.github.io/charts helm install keda kedacore/keda </code></pre> </div> <p>With KEDA, you can scale your LLM pods based on GPU utilization, HTTP traffic, or even Kafka topic lag.</p> <p><strong>Step 5: Monitoring with Prometheus + Grafana</strong></p> <p>Install full-stack observability:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm install monitoring prometheus-community/kube-prometheus-stack </code></pre> </div> <p>Expose a <code>/metrics</code> endpoint from your container.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>from prometheus_client import start_http_server, Summary import time REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request') @REQUEST_TIME.time() def process_request(): time.sleep(1) if __name__ == '__main__': start_http_server(8001) while True: process_request() </code></pre> </div> <p>Or use GPU exporters like <code>dcgm-exporter</code>. Grafana will pull all this into beautiful dashboards.</p> <p><strong>Step 6: Optional Components</strong></p> <ul> <li> <strong>Vector DB:</strong> Qdrant, Weaviate, or Chroma</li> <li> <strong>Auth Gateway:</strong> Add OAuth2 Proxy or Istio</li> <li> <strong>LangServe or FastAPI:</strong> Wrap your model with an API server or LangChain interface</li> <li> <strong>Persistent Volumes / Object Store:</strong> Save fine-tuned models using PVCs or MinIO</li> </ul> <p><strong>Final Thoughts</strong></p> <p>This isn’t just code. It’s the story of how I learned to stitch together powerful AI infrastructure from open-source tools and make it reliable enough for real-world teams to trust.</p> <p>Docker gave me modularity. Kubernetes gave me orchestration. GPUs gave me the muscle.</p> <p>Put together, they gave me something every AI builder wants: freedom.</p> <p>If you're tired of vendor lock-in and ready to roll up your sleeves, this cluster is your launchpad.</p> <p>This is just the beginning. Start building your GenAI infrastructure today and take control of your AI stack. Share your progress, contribute to the community, and let’s push the boundaries of what’s possible together.</p> <p>See you at the edge! 🌍</p> genai docker kubernetes llm From Zero to Local LLM: A Developer's Guide to Docker Model Runner Karan Verma Fri, 11 Apr 2025 16:29:17 +0000 https://dev.to/docker/from-zero-to-local-llm-a-developers-guide-to-docker-model-runner-4oi2 https://dev.to/docker/from-zero-to-local-llm-a-developers-guide-to-docker-model-runner-4oi2 <p><a href="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8nqc9c9d1z4pgw6q7a3.png" class="article-body-image-wrapper"><img src="proxy.php?url=https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr8nqc9c9d1z4pgw6q7a3.png" alt="docker arch" width="800" height="533"></a></p> <p><strong>Why Local LLMs Matter</strong></p> <p>Large language models have completely changed how we build apps, but most of them live in the cloud. That means you’re often stuck dealing with slow responses, expensive API calls, and worries about privacy or needing an internet connection. Running models locally on your own machine avoids all that, and you get faster, private, and offline-ready AI right at your fingertips.</p> <p>Docker Model Runner changes that it brings the power of container-native development to local AI workflows so you can focus on building, not battling toolchains.</p> <p><strong>The Developer Pain Points:</strong></p> <ul> <li> <strong>Privacy concerns</strong> - It’s tough to test safely when your data has to be sent to cloud APIs.</li> <li> <strong>High costs</strong> - Running prompts through paid APIs adds up fast, especially during early development and testing.</li> <li> <strong>Complicated setup</strong> - Getting a local model up and running usually means dealing with complex installs and hardware dependencies.</li> <li> <strong>Limited hardware</strong> - Many laptops just aren’t built to run large models, especially without a GPU.</li> <li> <strong>Hard to test different models</strong> - Switching between models or versions often means reconfiguring your entire setup.</li> </ul> <p><strong>Docker Model Runner solves these by:</strong></p> <ul> <li>Standardizing model access with a simple CLI that pulls models from Docker Hub </li> <li>Running fast with llama.cpp under the hood</li> <li>Providing OpenAI-compatible APIs out of the box</li> <li>Integrating directly with Docker Desktop</li> <li> <strong>Using GPU acceleration when available</strong> supports Apple Silicon (Metal) and NVIDIA GPUs on Windows for faster inference</li> </ul> <p>🐳 <strong>What Is Docker Model Runner?</strong></p> <p>It’s a lightweight local model runtime integrated with Docker Desktop. It allows you to run quantized models (GGUF format) locally, via a familiar CLI and an OpenAI-compatible API. It’s powered by <code>llama.cpp</code> and designed to be:</p> <p><strong>- Developer-friendly:</strong> Pull and run models in seconds<br> <strong>- Offline-first:</strong> Perfect for privacy and edge use cases<br> <strong>- Composable:</strong> Works with LangChain, LlamaIndex, etc.</p> <p><strong>Key Features:</strong></p> <ul> <li>OpenAI-style API served at:</li> </ul> <p><code>http://localhost:12434/engines/llama.cpp/v1/chat/completions</code></p> <ul> <li>GPU-free: works even on MacBooks with Apple Silicon and Windows 11 + NVIDIA GPUs</li> <li>Easily swap between models with the UX and CLI</li> <li>Integrated with Docker Desktop</li> </ul> <p><strong>Getting Started in 5 Minutes</strong></p> <p><strong>1. Enable Model Runner (Docker Desktop)</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>docker desktop enable model-runner --port 12434 </code></pre> </div> <p><strong>2. Pull Your First Model</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>docker model pull ai/smollm2:360M-Q4_K_M </code></pre> </div> <p><strong>3. Run a Model with a Prompt</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>docker model run ai/smollm2:360M-Q4_K_M "Explain the Doppler effect like I’m five." </code></pre> </div> <p><strong>4. Use the API (OpenAI-compatible)</strong><br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>curl http://localhost:12434/v1/completions \ -H "Content-Type: application/json" \ -d '{"model": "smollm2", "prompt": "Hello, who are you?", "max_tokens": 100}' </code></pre> </div> <p><strong>⚙️ Building Your Local GenAI Stack</strong></p> <p>Here's a simple architecture using Docker Model Runner as your inference backend:</p> <p><strong>- LangChain:</strong> For prompt templating and chaining<br> <strong>- Docker Model Runner:</strong> Runs the actual LLMs locally<br> <strong>- LlamaIndex:</strong> For document indexing and retrieval (RAG)<br> <strong>- React Frontend:</strong> Clean chat UI to interface with the model<br> <strong>- Docker Compose:</strong> One command to run them all</p> <p><strong>Sample Compose Example</strong><br> Here’s a <strong>sample</strong> <code>docker-compose.yml</code> showing how Docker Model Runner could fit into a local GenAI stack:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>services: chat: build: ./chat # Replace with your frontend app path or Git repo depends_on: - ai_runner environment: - MODEL_URL=${AI_RUNNER_URL} - MODEL_NAME=${AI_RUNNER_MODEL} ports: - "5000:5000" ai_runner: # Even if a service of type `model` is specified, # It doesn't run as a container — it runs directly on the host system via Docker Model Runner. provider: type: model options: model: ai/smollm2 # Specifies the local LLM to be used </code></pre> </div> <p><strong>Features:</strong></p> <ul> <li>Offline use with local model caching</li> <li>Dynamic model loading/unloading to save resources</li> <li>OpenAI-compatible API for seamless integration</li> <li>GPU acceleration support on compatible systems</li> </ul> <p>💡 <strong>Bonus: Add a Frontend Chat UI</strong></p> <p>Use any frontend framework (React/Next.js/Vue) to build a chat interface that talks to your local model via REST API.</p> <p>Simple example fetch:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>#!/bin/sh curl http://localhost:12434/engines/llama.cpp/v1/chat/completions \ -H "Content-Type: application/json" \ -d ' { "model": "ai/smollm2", "messages": [ { "role": "system", "content": "You are a helpful assistant." }, { "role": "user", "content": "Please write 500 words about the fall of Rome." } ] }' </code></pre> </div> <p>This gives you a fully local LLM setup that runs straight on your machine whether you're on a MacBook with Apple Silicon or a Windows PC with an NVIDIA GPU. No cloud APIs, no internet needed. Just local models running natively.</p> <p>🚀 <strong>Advanced Use Cases</strong></p> <p><strong>- RAG pipelines:</strong> Combine PDFs + local vector search + Model Runner<br> <strong>- Multiple models:</strong> Run phi2, mistral, and more in separate services<br> <strong>- Model comparison:</strong> Build A/B testing interfaces using Compose<br> <strong>- Whisper.cpp integration:</strong> Speech-to-text container add-ons (coming soon)<br> <strong>- Edge AI setups:</strong> Deploy on airgapped systems or dev boards</p> <p><strong>The Vision: Where This Is Headed</strong></p> <p><strong>Docker Model Runner Roadmap (Beta Stage):</strong></p> <ul> <li>Potential for a searchable, taggable ModelHub or Docker Hub registry</li> <li>Plans to support Compose-native GenAI templates</li> <li>Exploration of Whisper + LLM hybrid runners</li> <li>Development of a dashboard for monitoring model performance</li> <li>IDE integrations, such as VSCode extensions for prompt engineering and testing, are still under discussion and not yet available</li> </ul> <p><em>Note: Docker Model Runner is currently in Beta. Some features and integrations are in early stages or planning phases and may evolve over time.</em></p> <p>As a developer, I see this as a huge opportunity to lower the barrier for AI experimentation and help bring container-native AI to everyone.</p> docker devops opensource genai Building a Scalable Event-Driven Pipeline with MongoDB, Docker, and Kafka Karan Verma Fri, 04 Apr 2025 16:35:24 +0000 https://dev.to/docker/building-a-scalable-event-driven-pipeline-with-mongodb-docker-and-kafka-22a0 https://dev.to/docker/building-a-scalable-event-driven-pipeline-with-mongodb-docker-and-kafka-22a0 <p>In modern DevOps workflows, handling real-time data streams efficiently is crucial for building scalable applications. In this guide, we'll explore how to set up an event-driven pipeline using MongoDB, Docker, and Kafka to handle high-throughput data processing with ease.</p> <p>Imagine an e-commerce platform processing millions of orders in real time. Our setup ensures seamless, fault-tolerant data streaming between services.</p> <p><strong>1. Why Event-Driven Architectures?</strong></p> <p>Traditional architectures struggle with real-time processing, batch jobs, and scalability. Event-driven systems address these problems by:</p> <ul> <li>Decoupling components for greater scalability.</li> <li>Processing data in real-time instead of batch operations.</li> <li>Enhancing fault tolerance through asynchronous messaging.</li> </ul> <p>Kafka serves as the central message broker, while MongoDB acts as a persistent data store for event logs and structured data.</p> <p><strong>2. Setting Up MongoDB with Docker</strong></p> <p>To run MongoDB in a containerized environment, use the following Docker Compose setup:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>version: '3.8' services: mongodb: image: mongo:latest container_name: mongodb restart: always ports: - "27017:27017" environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: example volumes: - mongodb_data:/data/db volumes: mongodb_data: </code></pre> </div> <p>Run MongoDB with:</p> <p><code>docker-compose up -d</code></p> <p>Now, MongoDB is up and running on <strong>port 27017.</strong></p> <p><strong>3. Deploying Kafka in Docker</strong></p> <p>Kafka requires Zookeeper for coordination. We'll deploy both using Docker Compose:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>services: zookeeper: image: confluentinc/cp-zookeeper:latest container_name: zookeeper environment: ZOOKEEPER_CLIENT_PORT: 2181 ports: - "2181:2181" kafka: image: confluentinc/cp-kafka:latest container_name: kafka depends_on: - zookeeper ports: - "9092:9092" environment: KAFKA_BROKER_ID: 1 KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092 </code></pre> </div> <p>Start Kafka with:</p> <p><code>docker-compose up -d</code></p> <p>Check Kafka logs to confirm it's running:</p> <p><code>docker logs -f kafka</code></p> <p><strong>4. Connecting Kafka &amp; MongoDB</strong></p> <p>Kafka Connect enables data streaming between Kafka and MongoDB.</p> <p>Step 1: Install MongoDB Kafka Connector<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>docker exec -it kafka bash confluent-hub install mongodb/kafka-connect-mongodb:latest </code></pre> </div> <p>Step 2: Configure Kafka Connector</p> <p>Create a <code>mongo-sink.json</code> file:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>{ "name": "mongo-sink-connector", "config": { "connector.class": "com.mongodb.kafka.connect.MongoSinkConnector", "topics": "events", "connection.uri": "mongodb://root:example@mongodb:27017", "database": "eventDB", "collection": "eventLogs" } } </code></pre> </div> <p>Apply the configuration:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>curl -X POST -H "Content-Type: application/json" --data @mongo-sink.json http://localhost:8083/connectors </code></pre> </div> <p>Now, Kafka will stream events directly into MongoDB! 🚀</p> <p><strong>5. Scaling with Docker Swarm and Kubernetes</strong></p> <p>Deploying with Docker Swarm</p> <p>To deploy MongoDB and Kafka as a Swarm service, initialize Swarm:</p> <p><code>docker swarm init</code></p> <p>Deploy services:</p> <p><code>docker stack deploy -c docker-compose.yml event-pipeline<br> </code><br> Now, the services are running as a scalable stack!</p> <p>Deploying with Kubernetes and Helm</p> <p>To deploy Kafka and MongoDB on Kubernetes, use Helm charts:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>helm repo add bitnami https://charts.bitnami.com/bitnami helm install kafka bitnami/kafka helm install mongodb bitnami/mongodb </code></pre> </div> <p>This ensures high availability and fault tolerance.</p> <p><strong>6. Optimizing Docker Images for Performance</strong></p> <p>To build efficient and secure containers:</p> <ul> <li>Use small base images like Alpine: <code>FROM alpine:latest</code> </li> <li>Minimize layers with multi-stage builds.</li> <li>Use <code>.dockerignore</code> to exclude unnecessary files.</li> <li>Enable Docker BuildKit for faster builds:</li> </ul> <p><code>DOCKER_BUILDKIT=1 docker build .</code></p> <p><strong>7. Automating with DevOps Tools</strong></p> <ul> <li> <strong>CI/CD Pipelines:</strong> Automate deployment with Jenkins/GitHub Actions.</li> <li> <strong>Infrastructure as Code (IaC):</strong> Use Terraform or Kubernetes for scalable deployments.</li> <li> <strong>Monitoring &amp; Logging:</strong> Leverage Prometheus and Grafana for system health.</li> </ul> <p><strong>Final Thoughts</strong></p> <p>By integrating MongoDB, Kafka, and Docker, we've built a scalable event-driven pipeline. This setup is perfect for real-time analytics, log processing, and microservices architectures.</p> <p>💡 “How have you tackled event-driven architectures? Let’s discuss in the comments!”</p> docker kafka mongodb devops Optimizing Docker Image Builds for Speed & Efficiency Karan Verma Fri, 04 Apr 2025 15:56:39 +0000 https://dev.to/docker/optimizing-docker-image-builds-for-speed-efficiency-17b https://dev.to/docker/optimizing-docker-image-builds-for-speed-efficiency-17b <p><strong>The Problem: Slow Docker Builds are a Bottleneck</strong></p> <p>Docker images form the backbone of modern containerized applications, but slow image builds can significantly impact developer productivity. Every second wasted waiting for a build to complete adds up, slowing down CI/CD pipelines and delaying deployments.</p> <p>Common reasons for slow builds include:</p> <ul> <li>Large base images bloating the final image size</li> <li>Unoptimized Dockerfile instructions leading to inefficient caching</li> <li>Unnecessary dependencies increasing build times</li> <li>Frequent rebuilds due to changes in lower Dockerfile layers</li> </ul> <p><strong>The Solution: Optimize Your Dockerfile for Performance</strong></p> <p>By applying a few best practices, we can dramatically speed up Docker builds while keeping images lightweight and efficient.</p> <p><strong>1. Use a Minimal Base Image</strong></p> <p>Large base images slow down builds and increase attack surfaces. Instead, opt for lightweight images like Alpine Linux:</p> <p><code># Avoid large images like ubuntu:latest<br> FROM alpine:latest</code></p> <p>Why? Alpine is only ~5MB compared to Ubuntu (~29MB) or Debian (~22MB). This means smaller download sizes and faster builds.</p> <p><strong>2. Leverage Docker Build Caching</strong></p> <p>Docker caches layers from top to bottom. To maximize cache efficiency:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code># BAD: Installing dependencies AFTER copying source code invalidates cache FROM node:18-alpine WORKDIR /app COPY . . RUN npm install # ❌ Re-runs on every change CMD ["node", "index.js"] </code></pre> </div> <p>**Fix: **Move unchanging layers before copying source files:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code># GOOD: Dependencies installed first, source copied later FROM node:18-alpine WORKDIR /app COPY package.json package-lock.json ./ RUN npm install # ✅ Cached until package.json changes COPY . . CMD ["node", "index.js"] </code></pre> </div> <p>Now, unless <code>package.json</code> changes, <code>npm install</code> is cached, reducing rebuild time.</p> <p><strong>3. Use Multi-Stage Builds</strong></p> <p>Multi-stage builds keep final images clean by discarding unnecessary build dependencies.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code># Stage 1: Build dependencies FROM golang:1.20 AS builder WORKDIR /app COPY . . RUN go build -o myapp # Stage 2: Use a minimal runtime image FROM alpine:latest WORKDIR /app COPY --from=builder /app/myapp . CMD ["./myapp"] </code></pre> </div> <p><strong>Benefit:</strong> The final image only contains the Go binary, making it smaller &amp; faster.</p> <p><strong>4. Reduce Unnecessary Layers</strong></p> <p>Each <code>RUN</code> instruction creates a new layer. Minimize layers by chaining commands:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code># BAD: Multiple RUN commands create extra layers RUN apt-get update RUN apt-get install -y curl RUN rm -rf /var/lib/apt/lists/* </code></pre> </div> <p><strong>Fix:</strong> Combine them into a single <code>RUN</code> command:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code># GOOD: Reduces layer count RUN apt-get update &amp;&amp; \ apt-get install -y curl &amp;&amp; \ rm -rf /var/lib/apt/lists/* This minimizes image size and speeds up builds. </code></pre> </div> <p><strong>Use .dockerignore to Exclude Unnecessary Files</strong></p> <p>Docker builds everything in the build context. Exclude unnecessary files like logs, <code>node_modules</code>, and build artifacts:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>.dockerignore: node_modules/ .git/ *.log .env </code></pre> </div> <p>This reduces the build context size, leading to faster builds and reduced resource usage.</p> <p><strong>Final Thoughts</strong></p> <p>By following these best practices, you can significantly reduce Docker image size, improve build speed, and enhance CI/CD efficiency. Small optimizations can have big productivity gains!</p> docker devops softwareoptimization containerization