<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tyler Martinez on Medium]]></title>
        <description><![CDATA[Stories by Tyler Martinez on Medium]]></description>
        <link>https://medium.com/@slightlytyler?source=rss-9a079a670b41------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0umP5Fixx7aYhQaGhBNO0w.jpeg</url>
            <title>Stories by Tyler Martinez on Medium</title>
            <link>https://medium.com/@slightlytyler?source=rss-9a079a670b41------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:32:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@slightlytyler/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Containerizing modern front-end applications: Part 4— Package management and project administration]]></title>
            <link>https://medium.com/@slightlytyler/https-medium-com-slightlytyler-containerizing-modern-front-end-applications-part-4-1603eb62dbac?source=rss-9a079a670b41------2</link>
            <guid isPermaLink="false">https://medium.com/p/1603eb62dbac</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Tyler Martinez]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 17:38:55 GMT</pubDate>
            <atom:updated>2019-01-31T19:45:55.848Z</atom:updated>
            <content:encoded><![CDATA[<h3>Containerizing modern front-end applications with Docker, Webpack, and React: Part 4— Package management and project administration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*LgDR3VEsJIIsfB-WKdKtAw.jpeg" /></figure><p>In this final post in the series, I’m going to show you how we can add/remove dependencies and perform other project administration tasks in containers using the development image we’ve already built.</p><ul><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-1-c6aa6cb458a6">Part 1 — Building</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-2-5be2fde0be9f">Part 2 — Development environment</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-3-ee3397cd708d">Part 3 — Development processes</a></li></ul><h3>Cat picture app demo</h3><p>We’ll be using the same <a href="https://github.com/slightlytyler/docker-ui-demo">demo app</a> as the rest of this tutorial. It’s a cat picture app that pulls random pics from <a href="https://thecatapi.com/">The Cat API</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*k8aC9qq0E2XIGPgIXzFGFQ.gif" /><figcaption>😼😼😼</figcaption></figure><h3>Setup</h3><p>If you want to follow along at home here’s a quick setup.</p><pre>git clone <a href="https://github.com/slightlytyler/docker-ui-demo">https://github.com/slightlytyler/docker-ui-demo</a></pre><pre>cd docker-ui-demo</pre><pre>git fetch origin</pre><pre>git checkout -b follow-part-4 origin/start-part-4</pre><pre># and if you want to run yarn commands locally<br>yarn install</pre><h3>Package management</h3><p>Let’s start by adding a few packages. Right now we don’t have any styles so let’s use Emotion to add some. To do that we’d normally run a command like:</p><pre>yarn add @emotion/core @emotion/styled</pre><h4>Implementation</h4><p>To containerize this we’re going to need a new Make target that runs Yarn and also includes yarn.lock in the attached volumes. This is needed because commands like yarn add will mutate yarn.lock in addition to package.json. This target will be named run-yarn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/937ff20754afdbc628003e2a26902396/href">https://medium.com/media/937ff20754afdbc628003e2a26902396/href</a></iframe><h4>Running commands</h4><p>Let’s add those packages now.</p><pre># if you haven&#39;t built the image<br>make build-dev</pre><pre>make run-yarn ARGS=&quot;add @emotion/core @emotion/styled&quot;</pre><p>After the process completes you should see that package.json and yarn.lock have both been updated. You can verify that with Git.</p><pre>git diff package.json yarn.lock</pre><p>We can also use Yarn to verify the correct versions of our packages were installed.</p><pre>make run-yarn ARGS=&quot;list --pattern emotion&quot;</pre><h3>Let’s get to styling 💅</h3><p>The development image is now out of date with these changes to the packages so we need to update it before we can start using Emotion.</p><pre>make build-dev</pre><p>We can now run the development environment, import Emotion, and style our components.</p><pre>make run-dev API_URL=<a href="https://api.thecatapi.com/">https://api.thecatapi.com</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*zjMOy99bd0SMJ3pnwzofVw.gif" /><figcaption>💰</figcaption></figure><p>Ah yeah! Our app looks even better styled. Now let’s format and validate the changes.</p><pre>make run-fmt</pre><pre>make run-test</pre><h3>Done 🎉</h3><p>The app is now completely containerized, from the build process to project administration. I hope this series helps you harness the benefits of Docker and containers in your own front-end applications 👋.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1603eb62dbac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containerizing modern front-end applications: Part 3— Development processes]]></title>
            <link>https://medium.com/@slightlytyler/https-medium-com-slightlytyler-containerizing-modern-front-end-applications-part-3-ee3397cd708d?source=rss-9a079a670b41------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee3397cd708d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Tyler Martinez]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 17:38:48 GMT</pubDate>
            <atom:updated>2019-01-31T19:45:46.779Z</atom:updated>
            <content:encoded><![CDATA[<h3>Containerizing modern front-end applications with Docker, Webpack, and React: Part 3— Development processes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*wnuGMeUIro3Wq_2MhXgDhg.jpeg" /></figure><p>In the second part of the series, we got our development environment running inside a container. Now that we have that working I want to run other dev processes, like testing via Jest and formatting via Prettier, inside containers as well.</p><ul><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-1-c6aa6cb458a6">Part 1 — Building</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-2-5be2fde0be9f">Part 2 — Development environment</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-4-1603eb62dbac">Part 4 — Package management and project administration</a></li></ul><h3>Cat picture app demo</h3><p>We’ll be using the same <a href="https://github.com/slightlytyler/docker-ui-demo">demo app</a> as the rest of this tutorial. It’s a cat picture app that pulls random pics from <a href="https://thecatapi.com/">The Cat API</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*k8aC9qq0E2XIGPgIXzFGFQ.gif" /><figcaption>🙀🙀🙀</figcaption></figure><h3>Setup</h3><p>If you want to follow along at home here’s a quick setup.</p><pre>git clone <a href="https://github.com/slightlytyler/docker-ui-demo">https://github.com/slightlytyler/docker-ui-demo</a></pre><pre>cd docker-ui-demo</pre><pre>git fetch origin</pre><pre>git checkout -b follow-part-3 origin/start-part-3</pre><pre># and if you want to run yarn commands locally<br>yarn install</pre><h3>Development processes</h3><p>The first thing we’re going to containerize is our testing process. Right now we run that via a command like:</p><pre>yarn test</pre><h4>Implementation</h4><p>We’re actually really close already. We have an image with all of our dependencies and files and we have a method to run JS processes inside the container while sharing files between the host and the container. All the code we need to get this working is inside the Makefile.</p><p>So how do we run this within our development container? Let’s add a target to theMakefile. This target will be named yarn-test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8480a281ea448e8c20758fd2d36896c/href">https://medium.com/media/a8480a281ea448e8c20758fd2d36896c/href</a></iframe><h4>Running tests</h4><p>Now we can run our tests like:</p><pre># if you haven&#39;t built the image<br>make build-dev</pre><pre>make run-test</pre><p>We can also pass arguments to our test process, like running a test by name.</p><pre>make run-test ARGS=&quot;App&quot;</pre><h4>Other processes</h4><p>Ok, let’s containerize the formatting process as well. Right now we run that with a command like:</p><pre>yarn fmt</pre><p>We could add another target named run-fmt but this pattern doesn’t scale well. What if we had 10 more processes? 10 separate Make targets doesn’t sound great.</p><h4>A better abstraction</h4><p>Let’s use a little Make magic, specifically a dynamic target. This target will be named run-% and will act kind of like a wildcard, matching targets like run-fmt and run-test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/158f1bbd247b926f60271df9e0f0fce4/href">https://medium.com/media/158f1bbd247b926f60271df9e0f0fce4/href</a></iframe><blockquote>Note: we also added package.json and webpack.config.js to the volume mounts. fmt uses Prettier which will also format these files for us.</blockquote><h4>Magic 💫</h4><p>Now we can run any script defined in the package.json via the run-% target. Try formatting the code by making edits to the source and then run:</p><pre>make run-fmt</pre><p>Make sure the tests still pass afterward.</p><pre>make run-test</pre><h3>Done 🎉 … with part 3</h3><p>Now all of our development processes have been containerized.</p><p><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-4-1603eb62dbac">In the next, and last, part of this series</a> I’ll show how you can add / remove packages and perform other project administration tasks inside containers using this development image.</p><p>Next ➡️ <a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-4-1603eb62dbac">Part 4 — Package management and project administration</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee3397cd708d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containerizing modern front-end applications: Part 2— Development environment]]></title>
            <link>https://medium.com/@slightlytyler/https-medium-com-slightlytyler-containerizing-modern-front-end-applications-part-2-5be2fde0be9f?source=rss-9a079a670b41------2</link>
            <guid isPermaLink="false">https://medium.com/p/5be2fde0be9f</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Tyler Martinez]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 17:38:43 GMT</pubDate>
            <atom:updated>2019-01-31T19:45:40.340Z</atom:updated>
            <content:encoded><![CDATA[<h3>Containerizing modern front-end applications with Docker, Webpack, and React: Part 2— Development environment</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*pKRIifWYn0gYwfWBcQMFfg.jpeg" /></figure><p>In the first part of this series, I showed how we can containerize the build process for a front-end application. In this post, I’m going to cover containerizing the development environment utilizingwebpack-dev-server.</p><ul><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-1-c6aa6cb458a6">Part 1 — Building</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-3-ee3397cd708d">Part 3 — Development processes</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-4-1603eb62dbac">Part 4 — Package management and project administration</a></li></ul><h3>Cat picture app demo</h3><p>We’ll be using the same <a href="https://github.com/slightlytyler/docker-ui-demo">demo app</a> as the rest of this tutorial. It’s a cat picture app that pulls random pics from <a href="https://thecatapi.com/">The Cat API</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*k8aC9qq0E2XIGPgIXzFGFQ.gif" /><figcaption>😻😻😻</figcaption></figure><h3>Setup</h3><p>If you want to follow along at home here’s a quick setup.</p><pre>git clone <a href="https://github.com/slightlytyler/docker-ui-demo">https://github.com/slightlytyler/docker-ui-demo</a></pre><pre>cd docker-ui-demo</pre><pre>git fetch origin</pre><pre>git checkout -b follow-part-2 origin/start-part-2</pre><pre># and if you want to run yarn commands locally<br>yarn install</pre><h3>Development environment</h3><p>Currently, we would run the development environment like this:</p><pre>yarn run dev --env.api-url <a href="https://api.thecatapi.com/">https://api.thecatapi.com</a> --env.port 3000</pre><p>The goal now is to have this development environment run inside a container while reading the source files from the host filesystem. To do this we’re going to construct a development image that will let us easily run scripts via yarn inside the container and use Docker volumes to share files between the host filesystem and the container’s.</p><h4>Implementation</h4><p>Let’s start by adding a dev.Dockerfile in addition to our main Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7825bd340c6ea682f4a06a7dc8d78c1/href">https://medium.com/media/b7825bd340c6ea682f4a06a7dc8d78c1/href</a></iframe><p>No need add a separate .dockerignore, the current one will be respected.</p><h4>Let’s break that down</h4><pre>FROM node:11.1.0-alpine AS node_base</pre><p>The first stage defines our base image, the latest version of Node. This base image also includes Yarn.</p><pre>FROM node_base as deps<br>WORKDIR /usr/app<br>COPY package.json /usr/app/package.json<br>COPY yarn.lock /usr/app/yarn.lock<br>RUN yarn install</pre><p>The second stage installs our dependencies with Yarn.</p><pre>FROM node_base as dev<br>WORKDIR /usr/appCOPY --from=deps /usr/app/node_modules /usr/app/node_modules<br>COPY . /usr/app<br>ENTRYPOINT [&quot;yarn&quot;]</pre><p>The third and final stage copies over the dependencies from the second stage, then copies over the source files, and finally sets the entry point to the Yarn binary. This last part is critical. When we run our container with a command now it will be passed to Yarn rather than the shell, which is the default.</p><h4>Containerized</h4><p>Now we can run a Docker build command to build and tag our image.</p><pre>docker build -f dev.Dockerfile -t slightlytyler/docker-ui-demo-dev .</pre><p>Next, we can run the development environment.</p><pre>docker run -it --rm -p 3000:3000 slightlytyler/docker-ui-demo-dev dev --env.api-url <a href="https://api.thecatapi.com/">https://api.thecatapi.com</a> --env.host 0.0.0.0 --env.port 3000</pre><blockquote>Note: we had to change the binding address, via--env.host, to get this working inside the container.</blockquote><h4>That’s a lot of flags</h4><p>If we ignore some of the extraneous stuff this command is easier to parse.</p><pre>docker run $(DOCKER_ARGS) $(DOCKER_TAG) dev --env.api-url <a href="https://my-api.com/">https://my-api.com</a> --host 0.0.0.0 --env.port 3000</pre><p>When we run our development image the dev command is passed directly to the yarn binary, the ENTRYPOINT we defined earlier, along with the additional flags and arguments. This makes it super easy to execute JS processes inside the container via Yarn.</p><h4>Almost working</h4><p>The dev environment should now be running and available at localhost:3000, or port 3000 on whatever host Docker is available on your machine.</p><p>If you try to make changes to any of the files in your src directory you’ll notice that the app doesn’t update. The dev server should be watching for changes and reloading with updates… What gives?</p><h4>Volumes</h4><p>Well, right now the files we’re editing on our local system are not the same files inside the container. To make this work we’re going to have to use Docker volumes to share files between the host filesystem and the container’s.</p><pre>docker run -it --rm -p 3000:3000 -v $(PWD)/src:/usr/app/src slightlytyler/docker-ui-demo-dev dev --env.api-url <a href="https://my-api.com/">https://my-api.com</a> --env.host 0.0.0.0 --env.port 3000</pre><p>Now when we make edits to the source the app should update! 💥</p><h4>Further abstracting</h4><p>We can simplify the use of these commands by adding additional targets to our Makefile.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1431f04dad61e1375f8a42851f2d9f4d/href">https://medium.com/media/1431f04dad61e1375f8a42851f2d9f4d/href</a></iframe><h3>Running</h3><p>Now that we have our make targets defined the commands to build and run the development environment are much simpler.</p><pre>make build-dev</pre><pre>make run-dev API_URL=<a href="https://api.thecatapi.com/">https://api.thecatapi.com</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*JjWA4DLhjCxnstLpT44PEw.gif" /><figcaption>🐳</figcaption></figure><h3>Done 🎉 … with part 2</h3><p>Now we have a containerized front-end development environment.</p><p><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-3-ee3397cd708d">In the next part of the series</a>, I’ll show you how to containerize the other dev processes, like testing with Jest and formatting with Prettier.</p><p>Next ➡️ <a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-3-ee3397cd708d">Part 3 — Development processes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5be2fde0be9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Containerizing modern front-end applications: Part 1 — Building]]></title>
            <link>https://medium.com/@slightlytyler/https-medium-com-slightlytyler-containerizing-modern-front-end-applications-part-1-c6aa6cb458a6?source=rss-9a079a670b41------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6aa6cb458a6</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Tyler Martinez]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 17:38:18 GMT</pubDate>
            <atom:updated>2019-01-31T19:45:31.987Z</atom:updated>
            <content:encoded><![CDATA[<h3>Containerizing modern front-end applications with Docker, Webpack, and React: Part 1 — Building</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*RQ-AKcwhJw1pcGSX8Zg5Yw.jpeg" /></figure><p>If you’ve ever struggled with using Docker to build front-end applications this tutorial is for you. This series of posts will demonstrate how to effectively use Docker to develop, build, distribute, and run a front-end application utilizing technologies such as React, Webpack, Babel, and Yarn.</p><p>If you’ve never used Docker before (or are a little rusty) you might want to start somewhere <a href="https://docker-curriculum.com/">like here</a> and then come back to this tutorial. This tutorial assumes you are already comfortable with Docker, running shell commands, and the basics of building and operating web applications.</p><p>In this first part of the series, I’m going to cover containerizing the build process for the front-end app, running the app using a web server (in a container of course!), and techniques to distribute the app for use in production.</p><ul><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-2-5be2fde0be9f">Part 2 — Development environment</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-3-ee3397cd708d">Part 3 — Development processes</a></li><li><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-4-1603eb62dbac">Part 4 — Package management and project administration</a></li></ul><h3>Cat picture app demo</h3><p>The <a href="https://github.com/slightlytyler/docker-ui-demo">demo app</a> I’m using is a simple, single page application. I’ve built it without Docker during the initial iteration, using Yarn as the task runner and defining scripts in package.json. It’s a cat picture app that pulls random pics from <a href="https://thecatapi.com/">The Cat API</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*k8aC9qq0E2XIGPgIXzFGFQ.gif" /><figcaption>Exactly the kind of app this world needs.</figcaption></figure><h3>Setup</h3><p>If you want to follow along at home here’s a quick setup.</p><pre>git clone <a href="https://github.com/slightlytyler/docker-ui-demo">https://github.com/slightlytyler/docker-ui-demo</a></pre><pre>cd docker-ui-demo</pre><pre>git fetch origin</pre><pre>git checkout -b follow-part-1 origin/start-part-1</pre><pre># and if you want to run yarn commands locally<br>yarn install</pre><h3>Building</h3><p>Currently, the app is built like:</p><pre># after installing deps<br>yarn build</pre><p>The goal now is to run this process inside a container. The end result should be a Docker image that contains the distributable files (index.html, bundle.js, etc) and nothing else. This image isn’t runnable on its own and just serves as the distribution mechanism for the front-end assets during development (not at runtime). We’ll use this image later to build an example web server image that we can actually run.</p><h4>Implementation</h4><p>What does “containerizing” actually look like? First, we need to define the process of building the image using a Dockerfile.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9249c365e7603879a3120c20a319d97c/href">https://medium.com/media/9249c365e7603879a3120c20a319d97c/href</a></iframe><blockquote>Note: this uses<a href="https://docs.docker.com/develop/develop-images/multistage-build/"> multi-stage builds</a>, a technique utilized here to help reduce the size of our final image.</blockquote><p>We also need to add a .dockerignore as well so we don’t include local artifacts in our image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38914ca6def09f05f2280909b91d243f/href">https://medium.com/media/38914ca6def09f05f2280909b91d243f/href</a></iframe><h4>Let’s break that down</h4><pre>FROM node:11.1.0-alpine AS node_base</pre><p>The first stage defines our base image, the latest version of Node. This base image also includes Yarn.</p><pre>FROM node_base as deps<br>WORKDIR /usr/app<br>COPY package.json /usr/app/package.json<br>COPY yarn.lock /usr/app/yarn.lock<br>RUN yarn install</pre><p>The second stage installs our dependencies with Yarn.</p><pre>FROM node_base as build<br>WORKDIR /usr/app<br>COPY --from=deps /usr/app/node_modules /usr/app/node_modules<br>COPY . /usr/app<br>RUN yarn build</pre><p>The third stage copies our dependencies from the second stage and builds the distributable assets with Webpack.</p><pre>FROM scratch AS ui<br>COPY --from=build /usr/app/dist /usr/app</pre><p>In the fourth and final stage, we take a scratch (empty) image and copy over only the assets built during the third stage. Now we have an image that contains only the distributable assets for our front-end app.</p><h4>Actually building</h4><p>Now we can run a Docker build command to build and tag our image.</p><pre>docker build -t slightlytyler/docker-ui-demo .</pre><h4>Further abstracting</h4><p>Running Docker commands directly is OK but I’d much rather abstract away some of that complexity. We don’t want to make every developer remember that tag, right?</p><p>For that, we’re going to use GNU make and define a Makefile with a build target. This target will build our image and tag it with the current Git commit SHA and as latest.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b09c1fd746f93560bddfe205ea808443/href">https://medium.com/media/b09c1fd746f93560bddfe205ea808443/href</a></iframe><p>Running make build, or just make, should build the image and tag it appropriately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*ZMlQ2glLfXCB80M77zsjKQ.gif" /><figcaption>Building like a pro.</figcaption></figure><h3>Running</h3><p>Now that we have our built slightlytyler/docker-ui-demo image how do we actually run it? We’re going to use a Nginx image to build a simple web server, <a href="https://github.com/slightlytyler/docker-nginx-demo">example code here</a>. I’ve structured it as a separate project and Git repo, but you could easily do this in a different directory or even with a separate named Dockerfile.</p><p>Here’s the Dockerfile for the web server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a548167dfeb464178d895e6481eec3c8/href">https://medium.com/media/a548167dfeb464178d895e6481eec3c8/href</a></iframe><p>That’s it! This definition is very simple because all of the complexity of configuring Nginx to serve the SPA is built into socialengine/nginx-spa (check out the <a href="https://hub.docker.com/r/socialengine/nginx-spa/">README</a>). All we have to do is copy over the distributable files from slightlytyler/docker-ui-demo to the correct directory on the new web server image and everything works.</p><p>We can build the web server image:</p><pre>docker build -t slightlytyler/docker-nginx-demo .</pre><p>and run it:</p><pre>docker run -it --rm -p 8000:80 slightlytyler/docker-nginx-demo</pre><p>The app should now be available atlocalhost:8000 or port 8000 on whatever domain Docker is available on your machine.</p><h3>Distributing</h3><p>Now that we’ve built our images we need to push them up to a registry so that we can distribute our images to production environments and to other developers. It works like this:</p><ol><li>A developer pushes up an image after building it. This is often performed by a CI system but could be done by the developer manually from their local environment.</li><li>An operator pulls that image into a production environment where it is actually run. This is often performed by an orchestrator, like Kubernetes or Docker Swarm, but could be done by the operator manually from their remote environment.</li></ol><p>There is no CI for this tutorial so I will just push the images up manually to <a href="https://hub.docker.com/r/slightlytyler/docker-ui-demo/">Docker Hub</a>.</p><pre>docker push slightlytyler/docker-ui-demo</pre><pre>docker push slightlytyler/docker-nginx-demo</pre><p>If you want to do this part yourself you will need to change the tag var in the Makefile to your Docker Hub account’s namespace i.e. your-hub-name/docker-ui-demo.</p><h3>Done 🎉 … with part 1</h3><p>The build process is now containerized and we have a runnable image that serves the front-end application. The images are also pushed up to Docker Hub and are ready for distribution into production environments.</p><p><a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-2-5be2fde0be9f">In my next post</a>, I’ll show how containers can be utilized to make a development environment utilizingwebpack-dev-server.</p><p>Next ➡️ <a href="https://medium.com/@slightlytyler/containerizing-modern-front-end-applications-part-2-5be2fde0be9f">Part 2 — Development environment</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6aa6cb458a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>