<?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"><channel><title><![CDATA[Vite App Deployment on AWS EC2]]></title><description><![CDATA[Vite App Deployment on AWS EC2]]></description><link>https://vite-app-deployment-on-aws-ec2.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 24 Jun 2026 07:57:44 GMT</lastBuildDate><atom:link href="https://vite-app-deployment-on-aws-ec2.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Deploy Vite App on AWS EC2 with Docker]]></title><description><![CDATA[Modern frontend applications don’t stop at development — deployment is where real engineering begins.In this guide, we walk through a complete end-to-end workflow to build a Vite frontend app, containerize it using Docker, and deploy it on an AWS EC2...]]></description><link>https://vite-app-deployment-on-aws-ec2.hashnode.dev/how-to-deploy-vite-app-on-aws-ec2-with-docker</link><guid isPermaLink="true">https://vite-app-deployment-on-aws-ec2.hashnode.dev/how-to-deploy-vite-app-on-aws-ec2-with-docker</guid><category><![CDATA[AWS]]></category><category><![CDATA[vite]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Full Stack Development]]></category><category><![CDATA[Beginner Developers]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[EC2 instance]]></category><dc:creator><![CDATA[Uzair Qureshi]]></dc:creator><pubDate>Wed, 18 Feb 2026 02:05:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1771379943113/9663b3b6-0000-4531-8f3e-573278c9c840.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<p>Modern frontend applications don’t stop at development — deployment is where real engineering begins.<br />In this guide, we walk through a <strong>complete end-to-end workflow</strong> to build a <strong>Vite frontend app</strong>, containerize it using <strong>Docker</strong>, and deploy it on an <strong>AWS EC2 instance</strong>.</p>
<p>This project demonstrates a practical <strong>Frontend + DevOps</strong> setup that closely mirrors real-world workflows.</p>
<h2 id="heading-tech-stack-used"><strong>Tech Stack Used</strong></h2>
<ul>
<li><p><strong>Frontend:</strong> Vite + React</p>
</li>
<li><p><strong>Containerization:</strong> Docker</p>
</li>
<li><p><strong>Cloud Provider:</strong> Amazon Web Services</p>
</li>
<li><p><strong>Compute Service:</strong> Amazon EC2</p>
</li>
<li><p><strong>OS:</strong> Amazon Linux</p>
</li>
<li><p><strong>Version Control:</strong> GitHub</p>
</li>
</ul>
<hr />
<h2 id="heading-step-1-create-a-vite-application">Step 1: Create a Vite Application</h2>
<ol>
<li><p>Scaffold a Vite frontend application</p>
</li>
<li><p>Fetch data from a public dummy API (e.g., JSONPlaceholder)</p>
</li>
<li><p>Verify the app locally:</p>
</li>
</ol>
<pre><code class="lang-bash">npm run dev
</code></pre>
<p>✔️ Running locally first ensures the application is stable before Dockerization.</p>
<hr />
<h2 id="heading-step-2-create-a-dockerfile-development-mode">Step 2: Create a Dockerfile (Development Mode)</h2>
<p>Create a <code>Dockerfile</code> in the root of the project:</p>
<pre><code class="lang-dockerfile"><span class="hljs-keyword">FROM</span> node:<span class="hljs-number">20</span>

<span class="hljs-keyword">WORKDIR</span><span class="bash"> /aws-ec2-frontend</span>

<span class="hljs-keyword">COPY</span><span class="bash"> . .</span>

<span class="hljs-keyword">RUN</span><span class="bash"> npm install</span>

<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">5173</span>

<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"npm"</span>, <span class="hljs-string">"run"</span>, <span class="hljs-string">"dev"</span>, <span class="hljs-string">"--"</span>, <span class="hljs-string">"--host"</span>]</span>
</code></pre>
<h3 id="heading-dockerfile-breakdown">Dockerfile Breakdown</h3>
<ul>
<li><p><code>FROM node:20</code> → Uses Node.js 20 (required by modern Vite)</p>
</li>
<li><p><code>WORKDIR</code> → Defines the working directory inside the container</p>
</li>
<li><p><code>COPY . .</code> → Copies project files into the image</p>
</li>
<li><p><code>RUN npm install</code> → Installs dependencies</p>
</li>
<li><p><code>EXPOSE 5173</code> → Exposes Vite’s dev server port</p>
</li>
<li><p><code>--host</code> → Required to access the app via EC2’s public IP</p>
</li>
</ul>
<hr />
<h2 id="heading-step-3-create-a-dockerignore-file">Step 3: Create a <code>.dockerignore</code> File</h2>
<pre><code class="lang-plaintext">node_modules
dist
.git
.gitignore
Dockerfile
</code></pre>
<p>This reduces image size and speeds up Docker builds by excluding unnecessary files.</p>
<hr />
<h2 id="heading-step-4-push-code-to-github">Step 4: Push Code to GitHub</h2>
<ol>
<li><p>Create a new GitHub repository</p>
</li>
<li><p>Push:</p>
<ul>
<li><p>Vite source code</p>
</li>
<li><p><code>Dockerfile</code></p>
</li>
<li><p><code>.dockerignore</code></p>
</li>
</ul>
</li>
</ol>
<p>This enables easy cloning directly on the EC2 instance.</p>
<hr />
<h2 id="heading-step-5-create-an-ec2-instance">Step 5: Create an EC2 Instance</h2>
<p>Create an EC2 instance with the following configuration:</p>
<ul>
<li><p><strong>Instance Type:</strong> t3.micro</p>
</li>
<li><p><strong>OS:</strong> Amazon Linux</p>
</li>
<li><p><strong>Key Pair:</strong> Any existing key</p>
</li>
<li><p><strong>Security Group:</strong> Allow required ports</p>
</li>
</ul>
<p>Connect via SSH or AWS CLI.</p>
<hr />
<h2 id="heading-step-6-install-git-and-docker-on-ec2">Step 6: Install Git and Docker on EC2</h2>
<p>Run the following commands on the EC2 instance:</p>
<pre><code class="lang-bash">sudo yum update -y
sudo yum install git -y
git --version
</code></pre>
<pre><code class="lang-bash">sudo yum install docker -y
sudo systemctl start docker
sudo systemctl <span class="hljs-built_in">enable</span> docker
docker --version
</code></pre>
<ul>
<li><p>Git → Clone the repository</p>
</li>
<li><p>Docker → Build and run containers</p>
</li>
</ul>
<hr />
<h2 id="heading-step-7-clone-repository-amp-build-docker-image">Step 7: Clone Repository &amp; Build Docker Image</h2>
<h3 id="heading-clone-the-repository">Clone the Repository</h3>
<pre><code class="lang-bash">git <span class="hljs-built_in">clone</span> https://github.com/your-username/vite-app.git
<span class="hljs-built_in">cd</span> vite-app
</code></pre>
<h3 id="heading-verify-files">Verify Files</h3>
<pre><code class="lang-bash">ls
</code></pre>
<p>Expected output:</p>
<pre><code class="lang-plaintext">Dockerfile
package.json
src/
</code></pre>
<h3 id="heading-build-docker-image">Build Docker Image</h3>
<pre><code class="lang-bash">docker build -t vite-app .
</code></pre>
<h3 id="heading-run-the-container">Run the Container</h3>
<pre><code class="lang-bash">docker run -d -p 5173:5173 --name vite-container vite-app
</code></pre>
<h4 id="heading-command-explanation">Command Explanation</h4>
<ul>
<li><p><code>-d</code> → Runs container in detached mode</p>
</li>
<li><p><code>-p 5173:5173</code> → Maps EC2 port to container port</p>
</li>
<li><p><code>--name</code> → Assigns a readable container name</p>
</li>
</ul>
<hr />
<h2 id="heading-step-8-configure-ec2-security-group">Step 8: Configure EC2 Security Group</h2>
<p>Add an inbound rule:</p>
<ul>
<li><p><strong>Type:</strong> Custom TCP</p>
</li>
<li><p><strong>Port:</strong> 5173</p>
</li>
<li><p><strong>Source:</strong> 0.0.0.0/0</p>
</li>
</ul>
<p>This allows public access to the application.</p>
<hr />
<h2 id="heading-step-9-access-the-application">Step 9: Access the Application</h2>
<p>Open your browser:</p>
<pre><code class="lang-plaintext">http://&lt;EC2_PUBLIC_IP&gt;:5173
</code></pre>
<p>🎉 Your Vite frontend application is now live on AWS EC2!</p>
<hr />
<h2 id="heading-key-interview-takeaways">Key Interview Takeaways</h2>
<ul>
<li><p>Docker ensures environment consistency across systems</p>
</li>
<li><p><code>.dockerignore</code> improves build performance</p>
</li>
<li><p><code>--host</code> is required for external access in Vite</p>
</li>
<li><p>EC2 Security Groups act as virtual firewalls</p>
</li>
<li><p>Port mapping connects containers to host networking</p>
</li>
<li><p>Demonstrates a real-world frontend DevOps workflow</p>
</li>
</ul>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>This project demonstrates:</p>
<ul>
<li><p>Frontend development using Vite</p>
</li>
<li><p>Docker-based containerization</p>
</li>
<li><p>Cloud deployment with AWS EC2</p>
</li>
<li><p>A practical DevOps deployment pipeline</p>
</li>
</ul>
<p>With minor enhancements such as <strong>Nginx</strong>, <strong>production builds</strong>, and <strong>CI/CD pipelines</strong>, this setup can be made production-ready.</p>
<h2 id="heading-final-note">Final Note</h2>
<p>Feel free to <strong>fork</strong>, <strong>clone</strong>, and <strong>experiment</strong> with this project.<br />It’s an excellent hands-on example for interviews and real-world learning.</p>
<hr />
]]></content:encoded></item></channel></rss>