“I am My Last Witness.

When we learn to code, we all think about how to share our projects and ideas with others. Just give the code? The average person doesn’t understand. The environment needs a lot more. So deploy to the server, let the person be able to directly access, I think this should be the best way. With Docker, this convenience is made even more convenient.

Ali Cloud server Docker deployment front-end Vue project actual combat

One, foreword

I have installed all the mysql, Redis, etc I need before writing this blog. Install redis’ blog, which I wrote before.

Here only talk about how to put the project on the server docker to run, the environment or need to build their own.

Install what you use in your project in Docker. Project Environment:

Jdk11, mysql 5.7, redis

The project structure

If you want to highlight the Dockerfile file in idea, download the Docker plugin in idea

Ii. Specific steps:

1, into a JAR

1. Print the running project into a JAR package with Maven and test it locally first to see if there is any problem.

This is a SpringBoot project and when you click on maven’s package, it generates a JAR package

Then compile it on the command line.

Then test it in a browser. Let’s see if it works.

If successful, start writing the Dockerfile file.

2, Dockerfile contents

I’m using JDK11

FROM openjdk:11 # FROM: base image, starting with jdk8 image

COPY *.jar /app.jar  # COPY: COPY the application configuration file to the image as well.

CMD ["--server.port=8080"]

EXPOSE 8080  # EXPOSE: Declare the port
 
ENTRYPOINT ["java"."-jar"."/app.jar"]  
# ENTRYPOINT: The command that is run when docker starts, where jar services are run directly when the container starts.
Copy the code

3, upload

Upload the JAR package and dockerfile file to the server.

4. Package as a Docker image

I started by setting up the folder on the server….

I’m just going to go to this file and look at the file.

After checking, use Docker’s packaging command to package the two images together into one image. You have to have both of these under the same file.

docker build -t news_school_web1 .  
Copy the code

== Note: the most important first, the last is a decimal point, do not forget. = =

  • Docker bulid is the packing command
  • -t− Add a Tag to the image
  • The following news_school_web1 is the name given to the image
  • .The decimal point indicates the current directory, which is where Dockerfile resides

This is what success looks like

Of course, this is not enough, let’s enter the command to check. Let’s see if we have this mirror image.

docker images
Copy the code

5. Start the image

docker run -d -p 8686:8686 --name news_web_test news_school_web1
Copy the code
  • -D is running in the background
  • -p 8686:8686 is a port mapping
  • – the name names
  • News_school_web1 is the name of the image I packed.

To view

6, test,

  • First on the server test successful return to my page

  • Then test it on the Internet

    http:/ / IP address: 8686 / login
    Copy the code

I used a POST test, and a successful return of its own data indicates that the pull has been successfully run.

Daily self-talk

Think this time will be a good record of the process, can help yourself at the same time, and then help others. 😊