Cloud Native 9 min read

Step-by-Step Guide to Installing Docker, Nginx, MySQL and Deploying SpringBoot and Vue Projects with Docker

This tutorial provides a comprehensive walkthrough for installing Docker, Nginx, and MySQL, and demonstrates how to containerize and deploy a SpringBoot backend and a Vue frontend using Docker commands, Dockerfiles, and appropriate port and volume mappings.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Step-by-Step Guide to Installing Docker, Nginx, MySQL and Deploying SpringBoot and Vue Projects with Docker

1. Install Docker

Install Docker, manage its service, check version, run the hello‑world image and list all images.

yum install docker
service docker start
service docker stop
service docker restart
docker version
docker run hello-world
docker images

2. Install Nginx

Pull the Nginx image, view images, run a container with port mapping, verify it with curl, and perform extended operations such as entering the container, locating configuration files, copying them to host directories, and finally stopping and removing the container.

docker pull nginx
docker images
docker run -d --name nginx01 -p 3344:80 nginx
docker ps
curl localhost:3344
docker exec -it nginx01 /bin/bash
whereis nginx
exit
docker stop <container_id>
docker rm <container_id>
mkdir -p /data/nginx /data/nginx/www /data/nginx/conf /data/nginx/logs
docker cp <container_id>:/etc/nginx/nginx.conf /data/nginx/
docker cp <container_id>:/etc/nginx/conf.d /data/nginx/conf/
docker cp <container_id>:/usr/share/nginx/html/ /data/nginx/www/
docker cp <container_id>:/var/log/nginx/ /data/nginx/logs/
docker run --name nginx -p 80:80 -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/www/:/usr/share/nginx/html/ -v /data/nginx/logs/:/var/log/nginx/ -v /data/nginx/conf/:/etc/nginx/conf.d --privileged=true -d nginx

3. Install MySQL

Pull the MySQL image, view images, and run containers with custom names, port mappings, root passwords, optional restart policies, privileged mode, and volume mounts to persist data.

docker pull mysql
docker images
docker run --name mysql01 -d -p 3310:3306 -e MYSQL_ROOT_PASSWORD=root mysql
docker run --restart=always --privileged=true -d -v /home/mysql/data:/var/lib/mysql -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/my.cnf:/etc/mysql/my.cnf -p 3311:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=root mysql
docker ps

4. Deploy SpringBoot Project

Create a Dockerfile that uses a Java 8 base image, copies the built JAR, exposes the service port, and defines the entrypoint. Build the image, run a container, and test the API with Postman.

FROM java:8
COPY *.jar /app.jar
EXPOSE 9099
ENTRYPOINT ["java","-jar","app.jar"]

docker build -t api .
docker run -d -p 9099:9099 --name httapi api
docker ps

5. Deploy Vue Project

Prepare a default.conf for Nginx and a Dockerfile that copies the built Vue dist directory into the Nginx image, sets timezone, and exposes port 80. Build the image and run the container.

# default.conf
server {
    listen       80;
    server_name  ip_address;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }
    location /api {
        proxy_pass http://ip_address:port/;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html { root   html; }
}

# Dockerfile
FROM nginx
MAINTAINER htt
ENV TimeZone=Asia/Shanghai
COPY dist /usr/share/nginx/html/
COPY default.conf /etc/nginx/conf.d
EXPOSE 80

docker build -t vue .
docker run -d -p 8088:80 --name httvue vue
docker ps
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.

DeploymentcontainerizationVue
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

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.