<?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: Fitiavana Ramanandafy</title>
    <description>The latest articles on DEV Community by Fitiavana Ramanandafy (@fitiavana07).</description>
    <link>https://dev.to/fitiavana07</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%2F111357%2F97358af8-016d-460c-bf85-f6bc36df1c0d.jpeg</url>
      <title>DEV Community: Fitiavana Ramanandafy</title>
      <link>https://dev.to/fitiavana07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fitiavana07"/>
    <language>en</language>
    <item>
      <title>A production-ready Docker image for React</title>
      <dc:creator>Fitiavana Ramanandafy</dc:creator>
      <pubDate>Sun, 31 Jan 2021 20:08:03 +0000</pubDate>
      <link>https://dev.to/fitiavana07/a-production-ready-docker-image-for-react-3i4</link>
      <guid>https://dev.to/fitiavana07/a-production-ready-docker-image-for-react-3i4</guid>
      <description>&lt;p&gt;I made this Docker image so I can reuse it easily with every React project I dockerize or start from scratch. I open-sourced it so everyone can use it to move their app easily to production. Here is the GitHub URL: &lt;a href="https://github.com/fitiavana07/docker-react" rel="noopener noreferrer"&gt;https://github.com/fitiavana07/docker-react&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do I use it?
&lt;/h1&gt;

&lt;p&gt;Just copy this into a new Dockerfile.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# The first image is for compiling the client files, the second is for serving.&lt;/span&gt;

&lt;span class="c"&gt;# BUILD IMAGE&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;node:14-alpine&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;build-stage&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="c"&gt;# Install dependencies&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package*.json ./&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Build&lt;/span&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;npm run build

&lt;span class="c"&gt;# -----------------------------------------------------------------------------&lt;/span&gt;
&lt;span class="c"&gt;# SERVING IMAGE&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; fitiavana07/nginx-react&lt;/span&gt;

&lt;span class="c"&gt;# Copy built files&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; --from=build-stage /app/build /usr/share/nginx/html&lt;/span&gt;

&lt;span class="c"&gt;# 80 for HTTP&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 80&lt;/span&gt;

&lt;span class="c"&gt;# Run nginx&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; nginx -g 'daemon off;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  The stack
&lt;/h1&gt;

&lt;p&gt;I used Nginx to serve the built files, along with the config for serving React properly. The whole is bundled into the docker image &lt;code&gt;fitiavana07/nginx-react&lt;/code&gt;, so you don't need to worry about the config.&lt;/p&gt;

&lt;h1&gt;
  
  
  Does it support react-router?
&lt;/h1&gt;

&lt;p&gt;Yes, it supports react-router. All routes other than the root are handled properly.&lt;/p&gt;

&lt;p&gt;Suggestions are welcome.&lt;/p&gt;

</description>
      <category>react</category>
      <category>docker</category>
      <category>nginx</category>
    </item>
  </channel>
</rss>
