<?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: Thomas Sattlecker</title>
    <description>The latest articles on DEV Community by Thomas Sattlecker (@littlestudent).</description>
    <link>https://dev.to/littlestudent</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%2F51557%2F3e1525a8-11a5-4ecd-9cd4-657362425208.jpeg</url>
      <title>DEV Community: Thomas Sattlecker</title>
      <link>https://dev.to/littlestudent</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/littlestudent"/>
    <language>en</language>
    <item>
      <title>Docker For Your Dev Environment</title>
      <dc:creator>Thomas Sattlecker</dc:creator>
      <pubDate>Thu, 09 Aug 2018 21:36:14 +0000</pubDate>
      <link>https://dev.to/littlestudent/docker-for-your-dev-environment-41jp</link>
      <guid>https://dev.to/littlestudent/docker-for-your-dev-environment-41jp</guid>
      <description>&lt;p&gt;A few weeks ago I was thinking about how to make setting up an existing codebase of a frontend project easier for new employees or backend devs who rarely do this. To make this into a reliable process without running into a lot of downsides we can use &lt;code&gt;Docker&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Requirements for a solution
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Recompiling when changing a file has to be the same&lt;/li&gt;
&lt;li&gt;Compile times, especially initial compile time should not get any slower&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dockerfile
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node

RUN mkdir /app 
WORKDIR /app

COPY package.json /app/package.json
COPY package-lock.json /app/package-lock.json
RUN npm install

COPY ./config /app/config
COPY ./public /app/public
COPY ./src /app/src
COPY ./tests /app/tests
COPY ./.git /app/.git

RUN npm run build

CMD npm run start

EXPOSE 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build ./ -t web-devserver
docker run -it -p 3000:3000 -v $(pwd)/src:/app/src -v $(pwd)/config:/app/config -v $(pwd)/public:/app/public web-devserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;split the COPY entries in the Dockerfile. This makes incremental builds faster because as long as the copied files stay the same Docker can skip the step&lt;/li&gt;
&lt;li&gt;do a &lt;code&gt;RUN npm run build&lt;/code&gt; once so when &lt;code&gt;npm run start&lt;/code&gt; is compiling the project it only has to do an incremental build instead of a clean one.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docker run&lt;/code&gt; with option &lt;code&gt;-v&lt;/code&gt; mounts the corresponding folder into the Docker container. This enables the rebuilding on file changes.&lt;/li&gt;
&lt;/ul&gt;

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