{"id":16193,"date":"2025-10-11T08:23:42","date_gmt":"2025-10-11T13:23:42","guid":{"rendered":"https:\/\/design-buzz.com\/?p=16193"},"modified":"2025-10-11T08:23:43","modified_gmt":"2025-10-11T13:23:43","slug":"dockerize-orchestrate-a-mean-app-production-playbook-2025","status":"publish","type":"post","link":"https:\/\/design-buzz.com\/index.php\/2025\/10\/11\/dockerize-orchestrate-a-mean-app-production-playbook-2025\/","title":{"rendered":"Dockerize &amp; Orchestrate a MEAN App: Production Playbook 2025"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Reference :<\/h2>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/medium.com\/@mukesh.ram\/dockerize-orchestrate-a-mean-app-production-playbook-2025-0fd8543e62ed\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Production favors small, predictable containers and tight guardrails. You dockerize MEAN stack application layers, route traffic through a strict proxy, and expose health checks that tell the platform when to start, stop, or replace a service.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Compose supports a single host; clusters carry higher load and stricter uptime goals. With MEAN stack docker orchestration, you keep each piece independent, observable, and easy to roll back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide walks you through images, Docker Compose MEAN stack wiring, security basics, release tactics, and troubleshooting so that teams can ship clean updates on a steady cadence.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Dockerize Your MEAN Stack Application?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You dockerize MEAN stack application layers to lock consistency and speed. Containers turn local builds into repeatable releases. Teams ship faster, fix quicker, and keep costs predictable!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Tip:<\/em> Learn here the <a href=\"https:\/\/acquaintsoft.com\/blog\/build-ai-powered-mean-stack-web-apps\">best tips to build MEAN Stack web applications<\/a>!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Same build, everywhere. Package Angular, Node\/Express, and Mongo once. Run the same image in dev, staging, and prod. Your production MEAN Stack Docker flow stays stable.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Tight boundaries.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Give each service its own image and env. Cut side effects. Improve blast radius control during incidents.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Fast rollbacks. Tag images.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Revert with one pull and one restart. You deploy MEAN stack with Docker without drama.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Clean networking.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Route traffic through a proxy to the API. Keep Mongo on a private network. Your MEAN stack Docker orchestration story stays simple.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Portable ops.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Start on one host with Docker Compose MEAN stack. Move to Swarm or Kubernetes later without rewrites.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Smaller attack surface.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Use slim base images, non-root users, and strict headers. Reduce exposure across the stack.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Built-in health.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Expose \/healthz and \/readyz. Let the platform replace unhealthy containers.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Observable by default.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Send JSON logs to stdout. Track P95 per route. Instrument slow queries.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Lower on-call stress.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Standard images, health probes, and tagged releases shorten outages.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Cost control.&nbsp;<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Right-size CPU and memory per container. Scale the API and web tiers independently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites and Setup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Set up clean foundations before you Dockerize MEAN stack application services. A tidy baseline speeds local runs, staging tests, and production MEAN Stack Docker rollouts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install the essentials<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Engine or Docker Desktop v24+<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Compose v2 (Docker Compose CLI) for Docker Compose MEAN stack workflows<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Node.js 20.x and Angular CLI 17+ for local builds<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Git for version control; Make (optional) for quick scripts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A terminal with jq, curl, and wget for checks<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Shape a clear project layout<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">mean-app\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;web\/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Angular<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;src\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;package.json<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;angular.json<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;.dockerignore<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;ops\/nginx\/angular.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;api\/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Node\/Express<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;src\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;package.json<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;tsconfig.json<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;.dockerignore<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;ops\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;compose\/&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # docker-compose.yml and env samples<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;README.md<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep front-end and API separate. That separation improves MEAN stack docker orchestration later.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create .dockerignore files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reduce image size and build time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># web\/.dockerignore<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">node_modules<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dist<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.git<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.gitignore<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># api\/.dockerignore<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">node_modules<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">dist<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">coverage<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.git<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Define the environment early<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create minimal env files for local work; inject real secrets only at runtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># ops\/compose\/.env<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NODE_ENV=production<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">API_PORT=3000<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MONGO_URL=mongodb:\/\/mongo:27017\/app<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WEB_PORT=80<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Load secrets from the platform or a vault during deploy MEAN stack with Docker steps. <em>Never bake secrets into images.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Plan networks and ports<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Front door:<\/em> NGINX (web) listens on WEB_PORT<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>API:<\/em> Express listens on API_PORT, internal only<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Mongo:<\/em> private network only; map a port temporarily for local debugging<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Add health endpoints now<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>API:<\/em> \/healthz and \/readyz<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Web:<\/em> \/ returns index; use it for a basic probe<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Health checks let Compose or your orchestrator replace bad containers during production MEAN stack Docker rollouts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pick an image strategy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Angular:<\/em> multi-stage build \u2192 copy \/dist into nginx: alpine<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>API:<\/em> install deps in one stage, copy into a lean runtime, run as non-root<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Small images cut transfer time and attack surface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Write a simple NGINX conf<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Route \/api\/ to the API service<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Serve SPA routes with try_files \u2192 \/index.html<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set CSP, X-Content-Type-Options, and Referrer-Policy<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A strict edge improves reliability when you deploy MEAN stack with Docker behind a load balancer.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Add quick scripts (optional)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># Makefile<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">build:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker compose -f ops\/compose\/docker-compose.yml build<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Up:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker compose -f ops\/compose\/docker-compose.yml up -d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Logs:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose -f ops\/compose\/docker-compose.yml logs -f &#8211;tail=100<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Short commands keep the Docker Compose MEAN stack loop fast.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Decide on data<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Local development:<\/em> volume-backed Mongo container<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Production:<\/em> managed Mongo or replica set with backups<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This decision shapes your MEAN stack Docker orchestration plan and your recovery drills.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step-by-Step Guide to Dockerize a MEAN Stack Application<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Follow this sequence and dockerize MEAN stack application layers without guesswork. Build small images, add health checks, and keep configs clear.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You prepare the web (Angular + NGINX), the API (Node\/Express), and storage (Mongo) in tidy steps. This path sets you up for clean releases with Docker Compose MEAN stack, smooth rollouts for production MEAN stack Docker, and later MEAN stack Docker orchestration in a cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Prepare Angular for container builds<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Commands<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">cd web<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">npm ci<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">npm run build &#8212; &#8211;configuration=production<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Dockerfile<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># web\/angular.Dockerfile<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">FROM node:20-alpine AS build<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WORKDIR \/app<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY package*.json .\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RUN npm ci<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY . .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RUN npm run build &#8212; &#8211;configuration=production<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">FROM nginx:1.27-alpine<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY &#8211;from=build \/app\/dist\/ \/usr\/share\/nginx\/html\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY ops\/nginx\/angular.conf \/etc\/nginx\/conf.d\/default.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">EXPOSE 80<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">HEALTHCHECK &#8211;interval=30s &#8211;timeout=3s CMD wget -qO- http:\/\/127.0.0.1\/ || exit 1<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Notes<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use multi-stage builds to keep images lean.<\/li>\n\n\n\n<li>Keep dist\/ out of the build context with .dockerignore.<\/li>\n\n\n\n<li>Serve the SPA through NGINX for speed and cache control.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2) Route SPA and API with a strict NGINX config<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">NGINX config<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># web\/ops\/nginx\/angular.conf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">server {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;listen 80;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;server_name _;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;# API proxy<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;location \/api\/ {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;proxy_pass http:\/\/api:3000\/;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header X-Forwarded-Proto $scheme;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;proxy_set_header X-Request-ID $request_id;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;# SPA routes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;location \/ {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;root \/usr\/share\/nginx\/html;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;try_files $uri $uri\/ \/index.html;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;# Security headers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;add_header Content-Security-Policy &#8220;default-src &#8216;self&#8217;; connect-src &#8216;self&#8217;;&#8221; always;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;add_header X-Content-Type-Options &#8220;nosniff&#8221; always;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;add_header Referrer-Policy &#8220;no-referrer&#8221; always;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">}<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Why does it help?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">One front door simplifies deploying MEAN stack with Docker on any host.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Static files fly from NGINX; API traffic flows through \/api\/.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) Add health endpoints and logging to Express<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Express snippet<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/ api\/src\/app.ts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import express from &#8220;express&#8221;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import crypto from &#8220;crypto&#8221;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const app = express();<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">app.use((req, _res, next) =&gt; {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;(req as any).id = req.headers[&#8220;x-request-id&#8221;] || crypto.randomUUID();<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;next();<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">});<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">app.get(&#8220;\/healthz&#8221;, (_req, res) =&gt; res.status(200).send(&#8220;ok&#8221;));<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">app.get(&#8220;\/readyz&#8221;, (_req, res) =&gt; res.status(200).send(&#8220;ready&#8221;));<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">export default app;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Start file<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/ api\/src\/index.ts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">import app from &#8220;.\/app&#8221;;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">const port = process.env.PORT || 3000;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">app.listen(port, () =&gt; {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;console.log(<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;JSON.stringify({<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;level: &#8220;info&#8221;,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: &#8220;api up&#8221;,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mongoUrl: process.env.MONGO_URL ? &#8220;set&#8221;: &#8220;missing&#8221;,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;})<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">});<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Why does it help?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Health probes enable restarts before users feel pain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Request IDs make triage simple in production MEAN stack Docker runs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4) Build a lean API image<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Dockerfile<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># api\/api.Dockerfile<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">FROM node:20-alpine AS deps<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WORKDIR \/srv<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY package*.json .\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RUN npm ci &#8211;omit=dev<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">FROM node:20-alpine<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WORKDIR \/srv<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ENV NODE_ENV=production<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY &#8211;from=deps \/srv\/node_modules .\/node_modules<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">COPY . .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RUN addgroup -S app &amp;&amp; adduser -S app -G app<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">USER app<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">EXPOSE 3000<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">HEALTHCHECK &#8211;interval=30s &#8211;timeout=3s CMD wget -qO- http:\/\/127.0.0.1:3000\/healthz || exit 1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CMD [&#8220;node&#8221;, &#8220;dist\/index.js&#8221;]<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Why does it help?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Non-root user reduces risk.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Separate install stage cuts image weight and speeds pushes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5) Decide on Mongo for local and prod<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Local volume option (quick start)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># ops\/compose\/docker-compose.yml (mongo section)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mongo:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;image: mongo:7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;command: [&#8220;&#8211;bind_ip_all&#8221;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;volumes:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&#8211; mongo_data:\/data\/db<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;healthcheck:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;test: [&#8220;CMD&#8221;, &#8220;mongosh&#8221;, &#8220;&#8211;eval&#8221;, &#8220;db.adminCommand(&#8216;ping&#8217;)&#8221;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;interval: 30s<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;timeout: 5s<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Prod pointer (managed cluster)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Point MONGO_URL to a managed replica set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep credentials in a secret store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run smoke tests before you flip traffic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6) Wire everything with Compose<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Compose file (full stack)<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># ops\/compose\/docker-compose.yml<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">version: &#8220;3.9&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">sServices<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;api:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Build:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context: ..\/..\/api<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dockerfile: api.Dockerfile<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Environment:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; NODE_ENV=production<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; PORT=3000<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; MONGO_URL=${MONGO_URL:-mongodb:\/\/mongo:27017\/app}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;expose:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; &#8220;3000&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;depends_on:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mongo:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;condition: service_healthy<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;restart: always<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;healthcheck:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test: [&#8220;CMD&#8221;, &#8220;wget&#8221;, &#8220;-qO-&#8220;, &#8220;http:\/\/127.0.0.1:3000\/healthz&#8221;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;interval: 30s<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeout: 5s<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retries: 5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;Web:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Build:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;context: ..\/..\/web<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dockerfile: angular.Dockerfile<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Ports:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; &#8220;80:80&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;depends_on:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;api:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;condition: service_healthy<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;restart: always<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;Mongo:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;image: mongo:7<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Volumes:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; mongo_data:\/data\/db<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;restart: always<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;healthcheck:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test: [&#8220;CMD&#8221;, &#8220;mongosh&#8221;, &#8220;&#8211;eval&#8221;, &#8220;db.adminCommand(&#8216;ping&#8217;)&#8221;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;interval: 30s<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeout: 5s<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Volumes:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;mongo_data:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Commands<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">cd ops\/compose<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose up -d &#8211;build<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose logs -f &#8211;tail=100<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This file gives you a clean Docker Compose MEAN stack baseline that supports quick runs and safe retries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7) Smoke test the stack<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Checks<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">curl -sS http:\/\/localhost\/api\/healthz<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">curl -I http:\/\/localhost\/<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">docker compose ps<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm 200 OK from the API probe.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm NGINX serves the SPA.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm all services stay in a healthy status.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8) Add resource limits and graceful exits<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Compose resource hints<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">api:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;Deploy:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Resources:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Limits:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpus: &#8220;0.50&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory: &#8220;512M&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">web:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;Deploy:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Resources:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Limits:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpus: &#8220;0.25&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory: &#8220;256M&#8221;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Express shutdown<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/ api\/src\/index.ts (add)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">process.on(&#8220;SIGTERM&#8221;, () =&gt; {<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;console.log(JSON.stringify({ level: &#8220;info&#8221;, msg: &#8220;shutting down&#8221; }));<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;process.exit(0);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">});<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Limits and clean exits protect uptime during restarts in production MEAN stack Docker environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9) Keep secrets out of images<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store DB credentials and JWT keys in a vault or platform secrets.<\/li>\n\n\n\n<li>Load them as env vars at runtime.<\/li>\n\n\n\n<li>Print a redacted config summary on boot.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This practice reduces risk during deploying MEAN stack with Docker steps on any host.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10) Tag, push, and reuse images<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Build and tag<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker build -t registry.example.com\/mean-api:1.0.0 -f api.Dockerfile .\/api<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker build -t registry.example.com\/mean-web:1.0.0 -f angular.Dockerfile .\/web<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Push<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker push registry.example.com\/mean-api:1.0.0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker push registry.example.com\/mean-web:1.0.0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Versioned images unlock fast rollbacks and reliable MEAN stack Docker orchestration later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Orchestrating Your Containers for Production<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You run the same images everywhere and add control planes that scale, heal, and roll forward cleanly. Treat orchestration as guardrails around your app. Keep contracts simple, logs readable, and rollbacks instant.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These moves anchor MEAN stack Docker orchestration and turn \u201cworks on my machine\u201d into steady uptime for a real audience while you deploy MEAN stack with Docker after you Dockerize MEAN stack application services. Your production MEAN stack Docker story starts small with Docker Compose MEAN stack and grows into clusters without rewrites.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Start on one host with Compose.<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Define depends_on, healthchecks, and restart policies.<\/li>\n\n\n\n<li>Pin resource limits so noisy neighbors stop stealing CPU.<\/li>\n\n\n\n<li>Mount volumes only where you need persistence.<\/li>\n\n\n\n<li>Keep Mongo on a private network; publish only the web port.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This setup gives you a single-server runway for production MEAN stack Docker releases.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Scale example<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># burst API capacity on a single host<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose up -d &#8211;scale api=3<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Add simple clustering with Swarm (optional)<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a swarm, join nodes, and deploy a stack file.<\/li>\n\n\n\n<li>Use rolling updates with health checks and small batch sizes.<\/li>\n\n\n\n<li>Store secrets natively and inject them as files or env.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swarm keeps the Compose model and still supports rolling updates for MEAN stack Docker orchestration.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Stack snippet<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># swarm-stack.yml<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">services:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;api:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;image: registry\/mean-api:1.0.0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;Deploy:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replicas: 3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;update_config: { parallelism: 1, delay: 10s }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;restart_policy: { condition: on-failure }<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Move to Kubernetes when traffic grows.<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Model API and web as Deployments; expose them with Services.<\/li>\n\n\n\n<li>Terminate TLS at an Ingress; route \/api\/ to the API Service.<\/li>\n\n\n\n<li>Add readiness and liveness probes that mirror your health endpoints.<\/li>\n\n\n\n<li>Request CPU\/memory; set limits; enable autoscaling with HPA.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes brings strict MEAN stack Docker orchestration without new app code.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Ingress sketch<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">apiVersion: networking.k8s.io\/v1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">kind: Ingress<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">metadata: { name: mean-ingress }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">spec:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;Rules:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&#8211; http:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Paths:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; path: \/api\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pathType: Prefix<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backend: { service: { name: api-svc, port: { number: 3000 } } }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8211; path: \/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pathType: Prefix<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backend: { service: { name: web-svc, port: { number: 80 } } }<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Treat Mongo like real state<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prefer a managed Mongo cluster for production.<\/li>\n\n\n\n<li>If you must run it, use a StatefulSet, PersistentVolumeClaims, and proper backups.<\/li>\n\n\n\n<li>Keep backups on a schedule; run restore drills monthly.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">These rules protect data while you deploy MEAN stack with Docker at scale.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Roll out safely: blue\/green or canary<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Tag images with git sha; never deploy latest.<\/li>\n\n\n\n<li>Flip a small slice of traffic first; watch P95 and error rate.<\/li>\n\n\n\n<li>Roll forward when metrics stay green; roll back with one tag switch.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Secure the path by default<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Run containers as non-root; drop extra capabilities.<\/li>\n\n\n\n<li>Enforce strict CSP and CORS at the edge.<\/li>\n\n\n\n<li>Rate-limit auth routes; cap body sizes.<\/li>\n\n\n\n<li>Pull secrets from a vault; rotate keys on a calendar.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Wire full observability<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Send JSON logs to stdout; include requestId and short error codes.<\/li>\n\n\n\n<li>Track P50\/P95\/P99 per route, Mongo pool saturation, and slow query count.<\/li>\n\n\n\n<li>Add traces for the checkout or other hot flows; sample on high latency.<\/li>\n\n\n\n<li>Clear signals shrink MTTR across MEAN stack Docker orchestration paths.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Automate the release<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CI builds multi-stage images and runs unit\/integration tests.<\/li>\n\n\n\n<li>CI scans dependencies and images.<\/li>\n\n\n\n<li>CD pulls tags to staging, runs smoke tests, and promotes to production.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A clean pipeline pushes reliable Docker Compose MEAN stack runs and scales to clusters later.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Keep runbooks short and useful<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store one-page checklists for deploy, rollback, and incident triage.<\/li>\n\n\n\n<li>Include curl probes, log queries, and dashboard links.<\/li>\n\n\n\n<li>Update notes after each release.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Runbooks turn on-call panic into quick, repeatable action for production MEAN stack Docker work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deploying the Dockerized MEAN Stack Application<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Move from builds to users with a clean, repeatable path. You will deploy MEAN stack with Docker the same way every time: tag images, push to a registry, pull on the target, run health-aware services, smoke test, then cut DNS.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start on one host with Docker Compose MEAN stack; shift to clusters when traffic grows under your MEAN stack Docker orchestration plan. Keep the same images you used to dockerize MEAN stack application layers, so production MEAN stack docker runs stay predictable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Preflight checklist (prod target)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">OS up to date; Docker and Docker Compose installed<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Firewall rules: open 80\/443 to the proxy only<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DNS record ready; TLS cert path ready or ACME issuer set<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">.env file with real endpoints and secrets loaded from a vault<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Registry access: service account and pull permission for web and api images<\/li>\n\n\n\n<li>Monitoring endpoints reachable; alert rules ready<\/li>\n\n\n\n<li>Single-host rollout with Compose<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Pull tagged images<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker login registry.example.com<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker pull registry.example.com\/mean-web:1.0.0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker pull registry.example.com\/mean-api:1.0.0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Set environment<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">cd ops\/compose<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">cp .env.prod .env &nbsp; # includes WEB_PORT, API_PORT, MONGO_URL, secrets via platform<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Start services<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose up -d &#8211;build<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose ps<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose logs -f &#8211;tail=100 api<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Smoke test<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">curl -sS http:\/\/127.0.0.1\/api\/healthz<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">curl -I http:\/\/127.0.0.1\/<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Enable TLS<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Terminate TLS at NGINX or a cloud LB<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Point DNS at the LB; confirm 200s on https:\/\/your-domain<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Scale API during traffic spikes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose up -d &#8211;scale api=3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This path keeps deploying MEAN stack with Docker simply while you watch probes and logs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Blue\/green or canary on one host<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Run web-green and api-green with new tags in parallel<\/li>\n\n\n\n<li>Shift 10% of traffic via LB weight; watch P95 and error rate<\/li>\n\n\n\n<li>Promote to 100% if metrics stay green; otherwise, switch back in one command<\/li>\n\n\n\n<li>Roll back by swapping the LB target or by docker compose down for green<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Cluster rollout (Swarm or Kubernetes)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use clusters when uptime and scale matter more. Your MEAN stack docker orchestration rules stay the same: probes, limits, small batches, instant rollbacks.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Swarm stack deploy<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker swarm init<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker stack deploy -c swarm-stack.yml means<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker service ls<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker service update &#8211;image registry\/mean-api:1.0.1 &#8211;update-parallelism 1 &#8211;update-delay 10s mean_api<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Kubernetes rollout sketch<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl set image deploy\/api api=registry\/mean-api:1.0.1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl rollout status deploy\/api<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl get ingress<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Readiness probe gates traffic; liveness probe restarts unhealthy pods<\/li>\n\n\n\n<li>HPA scales on CPU or custom latency metrics<\/li>\n\n\n\n<li>Data and secrets in production<\/li>\n\n\n\n<li>Point MONGO_URL at a managed replica set<\/li>\n\n\n\n<li>Load DB creds and JWT keys from a vault or KMS; inject at runtime<\/li>\n\n\n\n<li>Rotate keys on a schedule; log rotations in the change log<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Observability during cutover<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Dashboards:<\/em> P50\/P95\/P99 per route, error rate, Mongo pool saturation<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Logs:<\/em> JSON with requestId and short error codes to stdout \u2192 collector<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Traces:<\/em> sample slow routes; tag spans with version for quick blame<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Rollback in seconds<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Compose:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose pull &amp;&amp; docker compose up -d &nbsp; # to promote<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose down &amp;&amp; docker compose -f docker-compose.prev.yml up -d &nbsp; # to revert<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Kubernetes:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl rollout undo deploy\/api<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl rollout undo deploy\/web<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Post-deploy checks<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Run a real user flow end to end (login \u2192 browse \u2192 write)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Verify cache headers and CSP at the edge<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm alerts stay quiet for 15\u201330 minutes under steady load<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Record version, tag, and changelog link in the release note<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting and Optimizations<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Production breaks in patterns. Spot the pattern, run a tiny probe, fix the smallest thing, then verify. Use this playbook to keep production MEAN stack Docker calm after you dockerize MEAN stack application services and before you scale with MEAN stack Docker orchestration or push with Docker Compose MEAN stack. You will still deploy MEAN stack with Docker fast, but you will do it with fewer late-night surprises.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1) Find the failing tier first<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Proxy:<\/em> wrong route or TLS rule \u2192 4xx\/5xx at the edge<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>API:<\/em> boot error, bad env, or hot path lock \u2192 5xx from \/api<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Mongo:<\/em> auth, network, or index gap \u2192 500 on read\/write routes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Web:<\/em> SPA route not rewired \u2192 404 on refresh<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Quick probes<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose ps<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose logs -f &#8211;tail=100 api<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">curl -sS http:\/\/127.0.0.1\/api\/healthz<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">curl -I http:\/\/127.0.0.1\/<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2) Fix common edge and SPA issues<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">502\/504 at NGINX: service name mismatch or dead upstream<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check proxy_pass http:\/\/api:3000\/; and container DNS<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm api reports a healthy status<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SPA refresh 404: missing try_files<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add try_files $uri $uri\/ \/index.html; in the web server block<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CORS pain: wrong Origin or header set<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reflect the correct domain, keep a tight allowlist, and send credentials only when required<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mixed content: HTTP asset on HTTPS page<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Switch asset URLs to HTTPS; set strict CSP<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3) Repair API boot and runtime faults<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Wrong env:<\/em> MONGO_URL missing or malformed<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Echo a redacted config line on boot; fail fast when required vars drop out<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Port conflict:<\/em> container listens on a different port than the proxy expects<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Align EXPOSE 3000, PORT=3000, and NGINX upstream<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Restart loop:<\/em> crash on startup<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Read logs, run the image locally with the same env, fix the first thrown error<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4) Stabilize Mongo quickly<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Auth failures:<\/em> wrong user, wrong DB, or SRV URL with old driver flags<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test with mongosh &#8220;&lt;MONGO_URL&gt;&#8221; &#8211;eval &#8220;db.adminCommand(&#8216;ping&#8217;)&#8221;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Slow queries:<\/em> missing index or unbounded scan<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the right compound index, cap result size, and use projections<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Pool saturation:<\/em> too many calls, not enough connections<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tune pool size; cache hot reads; debounce chatty endpoints<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5) End container resource thrash<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>OOMKilled:<\/em> process dies under load<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lower memory spikes (stream responses, chunk uploads), raise memory limit slightly, watch RSS<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>CPU throttle:<\/em> high latency on bursts<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cut blocking work, precompute hot data, scale API replicas with &#8211;scale api=N<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Slow TLS handshakes:<\/em> large cert chain or weak cache rules<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable keep-alive, tune cache headers for static files<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6) Lock in clean networking<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Keep Mongo on a private network; avoid public exposure<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Route all browser calls through the proxy at \/api\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set timeouts that reflect real work; return short error codes for quick blame<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7) Make logs, metrics, and traces useful<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Logs: JSON, a requestId, an error code, and a short message \u2192 stdout<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Metrics: P50\/P95\/P99 per route, error rate, Mongo pool saturation, slow query count<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Traces: sample slow requests; tag spans with version and requestId<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8) Shrink image size and attack surface<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Multi-stage builds, Alpine bases, .dockerignore for node_modules and dist<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy only the files you need; drop build tools from runtime layers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run as a non-root user; set strict permissions on app dirs<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9) Speed up the front end without regressions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Serve Angular assets from NGINX with long cache headers and content hashes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep the bundle lean: tree-shake, split chunks, drop unused polyfills<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use HTTP\/2 or HTTP\/3 at the edge when your platform supports it<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10) Roll out safely, roll back fast<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Tag images by commit SHA; never ship the latest<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ship a canary: 10% traffic \u2192 watch P95 and error rate \u2192 promote or revert<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep a one-line rollback per service in the runbook<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Runbook snippet<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"># promote<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose pull &amp;&amp; docker compose up -d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># revert (Compose)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">docker compose -f docker-compose.prev.yml up -d<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">11) Tune, compose, and cluster knobs that matter<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Compose: set healthchecks, restart: always, and resource limits<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swarm\/Kubernetes: set rolling update batch size, readiness probes, HPA rules<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">12) Verify a fix with one real flow<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Login \u2192 list \u2192 write \u2192 read back<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Compare dashboards before and after; keep screenshots in the ticket<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bottomline<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Treat containers as your release foundation. You dockerize MEAN stack application layers, route traffic through NGINX, and expose clear health probes. You keep configs simple, secrets safe, and images lean. You ship in small steps and keep rollback one command away.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start on one host with Docker Compose MEAN stack. Reuse the same images in a cluster for MEAN Stack Docker orchestration. Tag every build, watch P95 and error rate, and adjust limits before users feel pain. With that rhythm, you deploy MEAN stack with Docker confidently and maintain a steady production MEAN stack Docker cadence.<br>Acquaint Softtech builds containerized MEAN stacks end to end. The team dockerizes MEAN stack application services, writes multi-stage images, and sets up NGINX, probes, and CI\/CD. You start on Docker Compose MEAN stack and scale to clusters with clean MEAN stack Docker orchestration. <a href=\"https:\/\/acquaintsoft.com\/\">Acquaint Softtech<\/a> acts like a partner, not a vendor. Feel free to reach out to us anytime!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reference : Introduction Production favors small, predictable containers and tight guardrails. You dockerize MEAN stack application layers, route traffic through a strict proxy, and expose health checks that tell the&hellip;<\/p>\n","protected":false},"author":146,"featured_media":16194,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[2696,2695,2697,1627],"class_list":["post-16193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","tag-devops","tag-docker","tag-mean-stack","tag-web-development"],"_links":{"self":[{"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/posts\/16193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/users\/146"}],"replies":[{"embeddable":true,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/comments?post=16193"}],"version-history":[{"count":1,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/posts\/16193\/revisions"}],"predecessor-version":[{"id":16195,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/posts\/16193\/revisions\/16195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/media\/16194"}],"wp:attachment":[{"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/media?parent=16193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/categories?post=16193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/design-buzz.com\/index.php\/wp-json\/wp\/v2\/tags?post=16193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}