<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marco Bytes</title>
    <description>The latest articles on DEV Community by Marco Bytes (@marco_bytes_tech).</description>
    <link>https://dev.to/marco_bytes_tech</link>
    <image>
      <url>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%2Fuser%2Fprofile_image%2F3270252%2F367db376-c9cb-486c-bb49-416cdc1495b2.jpg</url>
      <title>DEV Community: Marco Bytes</title>
      <link>https://dev.to/marco_bytes_tech</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marco_bytes_tech"/>
    <language>en</language>
    <item>
      <title>How Windows Line Endings Broke My Docker Gradle Build (And How to Fix It)</title>
      <dc:creator>Marco Bytes</dc:creator>
      <pubDate>Fri, 20 Jun 2025 02:58:48 +0000</pubDate>
      <link>https://dev.to/marco_bytes_tech/how-windows-line-endings-broke-my-docker-gradle-build-and-how-to-fix-it-58m1</link>
      <guid>https://dev.to/marco_bytes_tech/how-windows-line-endings-broke-my-docker-gradle-build-and-how-to-fix-it-58m1</guid>
      <description>&lt;p&gt;Working with Java Spring Boot and Docker, I kept hitting this frustrating error during build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/bin/sh: ./gradlew: not found
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No matter what I tried, Docker just couldn’t run the Gradle wrapper inside the container. Turns out the culprit was something subtle — &lt;strong&gt;Windows CRLF line endings&lt;/strong&gt; on &lt;code&gt;gradlew&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What’s going on?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When you build a Docker image with a Java project using Gradle, the &lt;code&gt;gradlew&lt;/code&gt; file must be copied into the container and be executable.&lt;/li&gt;
&lt;li&gt;But if you’re on Windows, &lt;code&gt;gradlew&lt;/code&gt; often has &lt;strong&gt;CRLF (Carriage Return + Line Feed)&lt;/strong&gt; endings instead of Unix’s &lt;strong&gt;LF&lt;/strong&gt; endings.&lt;/li&gt;
&lt;li&gt;Linux-based containers can’t execute scripts with Windows line endings properly, so it throws a “not found” error.&lt;/li&gt;
&lt;li&gt;This problem is especially sneaky because your file looks fine on Windows and even inside Docker it shows up — but it silently fails when run.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How to confirm the issue?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Check line endings in your editor (VSCode, Notepad++ show line endings).&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;file gradlew&lt;/code&gt; on Linux — if it shows &lt;code&gt;CRLF&lt;/code&gt; line endings, that’s the issue.&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;RUN ls -la&lt;/code&gt; after &lt;code&gt;COPY&lt;/code&gt; in Dockerfile to confirm &lt;code&gt;gradlew&lt;/code&gt; is copied.&lt;/li&gt;
&lt;li&gt;Try running &lt;code&gt;chmod +x ./gradlew&lt;/code&gt; — no errors but still &lt;code&gt;./gradlew: not found&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How to fix it?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Option 1: Fix on your host machine (best)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use tools like &lt;code&gt;dos2unix gradlew&lt;/code&gt; locally before building.&lt;/li&gt;
&lt;li&gt;Configure your Git to checkout with LF line endings:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  git config --global core.autocrlf input
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Set your editor to save files with LF endings.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Option 2: Fix inside Dockerfile (if host fix is impossible)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;RUN &lt;/span&gt;apk add &lt;span class="nt"&gt;--no-cache&lt;/span&gt; dos2unix &lt;span class="se"&gt;\
&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; dos2unix ./gradlew &lt;span class="se"&gt;\
&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;chmod&lt;/span&gt; +x ./gradlew
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Final Dockerfile snippet example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apk add &lt;span class="nt"&gt;--no-cache&lt;/span&gt; dos2unix &lt;span class="se"&gt;\
&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; dos2unix ./gradlew &lt;span class="se"&gt;\
&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;chmod&lt;/span&gt; +x ./gradlew

&lt;span class="k"&gt;RUN &lt;/span&gt;./gradlew bootJar &lt;span class="nt"&gt;--no-daemon&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This tiny line endings mismatch wasted hours of debugging for me, but now you know the trick to avoid it.&lt;/p&gt;

&lt;p&gt;Make sure to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check your line endings,&lt;/li&gt;
&lt;li&gt;Convert them properly,&lt;/li&gt;
&lt;li&gt;And always test inside your container early.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This simple fix will save you headaches and speed up your Docker + Gradle builds!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>springboot</category>
      <category>build</category>
    </item>
  </channel>
</rss>
