Step-by-Step Docker‑Compose Guide to Deploy a SpringBoot‑Vue‑Redis‑MySQL Stack
This article walks through installing Docker and Docker‑Compose, creating a project directory, writing a docker‑compose.yml that defines Redis, MySQL, Nginx, Java, and a file‑preview service, configuring each container, and using docker‑compose commands to build, start, monitor, and manage the full SpringBoot‑Vue application stack.
docker-compose
Overview
docker-compose is an open‑source project hosted on GitHub, implemented in Python, that calls the Docker Engine API to orchestrate a group of related containers defined in a single YAML file. It isolates environments by project name, giving each project its own Docker network on the same host.
Implementation
Prerequisites
Verify that Docker and Docker‑Compose are installed on the server:
docker --version
docker-compose --versionDirectory layout
Create a project directory (e.g., fzysShow) and inside it create the following sub‑directories and files:
docker-compose.yml java/– place the backend JAR fzys.jar here mysql/data/ – MySQL data volume nginx/config/nginx.conf – Nginx configuration file nginx/font/dist/ – built Vue static files nginx/log/ – log volume redis/redis.conf and redis/data/ – Redis configuration and data
docker-compose.yml
Populate docker-compose.yml with the following content (version 3.8):
version: "3.8"
services:
redis:
image: redis:latest
restart: always
ports:
- "36379:6379"
volumes:
- ./redis/redis.conf:/etc/redis/redis.conf
- ./redis/data:/data
command: redis-server /etc/redis/redis.conf
mysql:
image: mysql:latest
restart: always
ports:
- "33306:3306"
command: --lower_case_table_names=1
environment:
MYSQL_DATABASE: fzys-show
MYSQL_ROOT_PASSWORD: Fzys@123!
MYSQL_ROOT_HOST: '%'
TZ: Asia/Shanghai
volumes:
- ./mysql/data:/var/lib/mysql
kkfileview:
image: zjblovewl/kkfile:4.9
ports:
- "38012:8012"
nginx:
image: nginx:latest
ports:
- "390:390"
volumes:
- ./nginx/font/dist:/usr/share/nginx/dist
- ./nginx/log:/var/log/nginx
- ./nginx/config/nginx.conf:/etc/nginx/nginx.conf
java:
image: openjdk:8u342-oracle
restart: always
volumes:
- ./java:/home
working_dir: /home/
ports:
- "39090:39090"
- "38901:8901"
environment:
TZ: Asia/Shanghai
depends_on:
- redis
- mysql
command: ['java','-jar','/home/fzys.jar']Service configuration details
Redis : Uses the latest image, maps host port 36379 to container 6379, mounts a custom redis.conf and a data directory, and starts with redis-server /etc/redis/redis.conf. Ensure the configuration file is readable inside the container (e.g., chmod -R 777 redis.conf).
MySQL : Uses the latest image, maps host port 33306 to container 3306, runs --lower_case_table_names=1 to ignore case, and sets environment variables for database name, root password, host access, and timezone. Data persists in ./mysql/data.
kkfileview : Optional file‑preview service; can be omitted if not required.
Nginx : Maps host port 390 to the container, mounts the built Vue static files into /usr/share/nginx/dist, mounts logs, and mounts a custom nginx.conf. The configuration defines a worker process, client body size limit, static file handling, a reverse‑proxy for the backend API ( /prod-api/), and a WebSocket proxy (which may be removed if unused).
Java : Uses an OpenJDK 8 image, mounts the ./java directory, sets the working directory to /home/, maps two ports for the application, inherits the timezone, declares dependencies on Redis and MySQL to enforce start order, and runs the backend JAR with java -jar /home/fzys.jar.
Start the stack
From the directory containing docker-compose.yml run: docker-compose up Running without -d keeps the containers in the foreground, allowing direct log observation. After the services start, MySQL will have created the database but no tables; import the required SQL manually or copy tables using a client tool.
Common docker‑compose commands
docker compose ps– list all services in the current project. docker compose build – build images defined in the compose file. docker compose up – start containers in the foreground; add -d for detached mode. docker compose stop – stop all containers. docker compose start – start stopped containers. docker compose restart – restart containers (service name optional). docker compose down – stop and remove containers and networks, preserving volumes. docker compose logs – view logs for all services or a specific one.
Verification
After docker-compose up, all services should show status Up. Access the server on port 390; the Nginx page with a captcha indicates successful deployment.
Updating the front‑end
Replace the contents of ./nginx/font/dist with a new build of the Vue application and restart Nginx: docker-compose restart nginx Ensure the uploaded directory contains only the built dist files (no nested dist sub‑directory).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
The Dominant Programmer
Resources and tutorials for programmers' advanced learning journey. Advanced tracks in Java, Python, and C#. Blog: https://blog.csdn.net/badao_liumang_qizhi
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
