Complete process of project packaging and deployment to Docker environment

The following is the complete process of packaging and deploying front-end projects and back-end Java projects to a Docker environment

Front-end project deployment

  1. Use front-end build tools (such as Webpack, Vue CLI, Create React App) to package front-end projects into static files.

  2. Create a Dockerfilefile named with the following content:

    # 使用基础镜像
    FROM nginx:latest
    
    # 将打包好的静态文件复制到Nginx的默认HTML目录
    COPY /dist /usr/share/nginx/html
    
    # 暴露Nginx的默认HTTP端口
    EXPOSE 80
    
    # 启动Nginx服务器
    CMD ["nginx", "-g", "daemon off;"]
    

3. Build the Docker image using the following command:

 docker build -t frontend-app .

4. Run the following command to start the front-end container:

docker run -d --name frontend-container -p 80:80 frontend-app

5. Now you can access http://localhost through the browser to view the deployed front-end application.

Backend Java project deployment

1. Make sure your backend Java project has been built and generated a runnable JAR file.

2. Create a file named Dockerfile with the following content:

# 使用基础镜像
FROM openjdk:latest

# 将可运行的JAR文件复制到容器内指定位置
COPY /path/to/your/app.jar /app/app.jar

# 暴露应用程序的默认端口
EXPOSE 8080

# 启动应用程序
CMD ["java", "-jar", "/app/app.jar"]

3. Build the Docker image using the following command:

docker build -t backend-app .

4. Run the following command to start the backend container:

docker run -d --name backend-container -p 8080:8080 backend-app

5. The API interface of the back-end application can now be accessed through a browser or other tools.

Note: frontend-app and backend-app in the above command are the names of the images. You can name them according to the actual situation.

Guess you like

Origin blog.csdn.net/weixin_41902931/article/details/130744363