Docker deploys the springboot project

1. Package the springboot project into a jar package
    and enter the directory where the project is located (and where the pom.xml file is located) through the cmd command to execute the command: mvn package. If no error is reported, the executable jar package of the project (for example: demo-0.0.1-SNAPSHOT.jar) is generated in the target directory. The generated jar package can be executed in the target directory through java -jar.

2. Create an image
  1. Create a Dockerfile (no suffix name) The configuration is as follows:
 # Specify a basic image centos
FROM docker.io/centos:latest #Install
 
the application execution environment java
RUN yum -y install java #Copy
 
the specified jar file To the container
COPY demo-0.0.1-SNAPSHOT.jar /usr/local/ #Container

open port
EXPOSE 8080  #Execute

jar file
ENTRYPOINT ["java" ,"-jar","/usr/local/demo-0.0. 1-SNAPSHOT.jar"]
Explanation: 
FROM ; the underlying image used 
RUN : The instruction tells docker to execute the command in the image and what is installed. .
EXPOSE: The command is used to tell Docker which ports the container will listen on when it is running, that is, these ports are bound to the machine 

"-Djava.security.egd=file:/dev/./urandom" prevents multiple instances from being launched in a container 

Upload the packaged jar package of the project to this directory in the Dockerfile directory

2. The command to create the image is as follows:
 docker build -t hero/test:dev .
Explanation: 
. : Indicates the directory where the Dockerfile file is located, you can specify the absolute path of the 
Dockerfile- t: Specify 
the ": " after the name of the image name: represents the tag, which is 1.0

3 View the image
docker images

3. Start the container
1. Use the image to create a container

Docker command: docker run -p ip:hostPort:containerPort redis
uses the -p parameter The port mapping of the host machine is assigned to the virtual machine. 
IP represents the IP address of the host. 
hostPort indicates the port of the host. 
containerPort represents the port of the virtual machine.

docker run -d -p 8080:8080 hero/test:dev

2. View the running container
docker ps

4. Test

  Enter the external network ip: 8080/ in the browser to access the project interface




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325922407&siteId=291194637