Detailed steps to run the front-end and back-end projects to the server through docker and solutions to problems that arise

Requirements (operation and maintenance related)

Need to publish the project to the server through the mirror, and then link the log to granfa.

The required technology and steps

technology:

Docker command
auto-config plug-in use
linux environment command

step:

  1. The back-end project is packaged through the specified configuration file (auto-config plug-in is configured), the command is

mvn clean install -Dmaven.test.skip=true -Dautoconfig.userProperties=/Users/xxx/xxx/application.properties
followed by the path of your specified configuration file (here how to configure this plugin to use Baidu by itself, an error occurred Just check where it is wrong)

  1. After the packaging is completed, a Dockerfile needs to be configured to package the image, a general dockerfile

FROM java:8
COPY *.jar /app.jar
CMD ["–server.port=8080"]
EXPOSE 8080
ENTRYPOINT [“java”,"-jar",“app.jar”]

  1. Use the scp command to transfer these files to the server. I need to go through the springboard first, so first transfer to the springboard and then to the service. If it shows that there is no permission, you can first transfer to the /tmp temporary file storage area. And then send

scp /Users/xxx/Desktop/xxx Server address: /tmp
If the transmission is a folder, then add a -r cycle reading.

  1. Enter the server, put the Dockerfile and the project's jar package in a folder, and then directly run docker build to package into a mirror, and then run it to complete the production, you can use the -v command to mount the log output to the server, Otherwise, it's always in the container
  2. The front-end project is to start the front-end project through the nginx mirror, and requires a nginx configuration to start. The general configuration is as follows
server {
  listen       80;
  server_name  localhost;

  location ~ ^/xxx/* {
    proxy_pass http://localhost:8080;
  }

  location / {
    try_files $uri $uri/ /index.html;
    root /usr/xxx/xxx;
    index index.html index.htm;
  }

  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /usr/share/nginx/html;
  }
}

The configuration of nginx reverse proxy forwards the request of port 80 to port 8080. The packaging command is the same as before. You only need to mount this default.conf to the container when you start the nginx mirror.
6. Configure in the front end The problem when:

The reason for reporting 403 directly is that user nginx or user nobody is used in nginx's default configuration file nginx.conf, which will cause no permission to start.

Then there is project 502 because the default seLinux mode of the server is strict mode, and the default value of seLinux in conf needs to be modified in /etc/seLinux, which needs to be restarted. But you can also turn this off temporarily, the command is setenforce 0 to turn off, and then change the localhost of the configuration file to the domain name of the server, which will solve the gateway restriction problem

You can learn more about docker commands such as how to mount data volumes. I will not list them here.

Guess you like

Origin blog.csdn.net/xiaole060901/article/details/112859785