Operations 7 min read

One-Command Docker Compose: Deploy Full-Stack Projects Instantly

This guide walks through using Docker Compose to package and launch a complete full‑stack application—including a React front‑end, an Express back‑end, and a MariaDB database—with a single command, covering prerequisites, Dockerfiles, Nginx configuration, and runtime management.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
One-Command Docker Compose: Deploy Full-Stack Projects Instantly

Introduction

Many open‑source projects are difficult to run locally because they require multiple environments and dependencies; Docker Compose can simplify this by orchestrating containers for the front‑end, back‑end, and database with a single docker compose up -d command.

Prerequisites

Docker installed and running

docker‑compose (installed automatically with Docker)

A React SPA project

An Express back‑end project

Front‑end Project Build

Start with a CRA template, configure environment detection, add Axios for API calls, and build the production assets using yarn build:prod. The resulting build folder contains the static files to be served.

Deploying with Nginx

Run an Nginx container to serve the static assets:

docker run -d -p 80:80 -v /path/to/build:/usr/share/nginx/html --name frontend-test nginx

Because the React router runs on the client side, a custom default.conf is added to rewrite all requests to index.html:

server { listen 80; server_name localhost; root /home/frontend; location / { try_files $uri $uri/ @router; index index.html; } location @router { rewrite ^.*$ /index.html last; } }

Dockerfile for Front‑end

FROM nginx
WORKDIR /home/frontend
COPY build .
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

Build and run the image:

docker build -t frontend .
docker run -d -p 80:80 --name frontend-v1 frontend
Remember to stop any container using port 80 before starting a new one.

Database Setup

Start a MariaDB container (used instead of MySQL on M1 Macs):

docker run -p 3306:3306 --restart=always --privileged=true --name mysql -v /Users/user/Desktop/mysql/data:/var/lib/mysql -v /Users/user/Desktop/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD="123456" -d mariadb

Configuration files set character set, authentication plugin, and SQL mode.

Back‑end Project Deployment

Express Project

Clone an Express template, connect it to the MariaDB instance, and ensure it runs locally.

Process Management with PM2

module.exports = { apps : [{ name: "myapp", script: "./bin/www", watch: true, env: { "NODE_ENV": "development" }, env_production: { "NODE_ENV": "production" } }] };

Start the appropriate environment:

pm2 start pm2.config.js --env development
pm2 start pm2.config.js --env production

Dockerfile for Back‑end

FROM keymetrics/pm2
RUN mkdir -p /home/backend
WORKDIR /home/backend
# (Copy source code and install dependencies here)
EXPOSE 3000

Build and run the back‑end image similarly to the front‑end.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerReactNginxExpressDocker ComposeMariaDBFull‑Stack Deployment
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.