1. Prepare jdk and spring boot small projects that need to be run.
Unzip the jdk compressed package to the directory where Dockerfile is located, and copy the spring boot small project websocket.jar to the directory where Dockerfile is located:
2. Create a Dockerfile file with the following contents:
Centos 2 1? 3 Defender Yao Lin 4? 5 Copy JDK1.7.0 _ 79 JDK1.7.0 _ 79 6 Add websocket.jar app.jar 7? 8 ENV JAVA _ HOME =/JDK 1 . 7 . 0 _ 79 9 ENV PATH = $ JAVA _ HOME/bin:$ PATH 10 ENV class PATH =。 :$ JAVA _ HOME/lib/dt . jar:$ JAVA _ HOME/lib/tools . jar 1 1 12 EXPOSE 8080 13 14 entry point[" JAVA ","-jar ","/app.jar"]
Specify the reference mirror center
Designated Maintainer Information Lin Yao
Copy jdk
Add the spring boot applet and rename it app.jar
Configure jdk environment
Expose port 8080
Specifies that the execution starts the spring boot applet.
3. Compile and generate images (. Represents the current path)?
docker build -t yaolin/websocket。
4. View the generated image?
Docker image
5. Create a container and run it.
docker run-p 192. 168.0 . 105:8080:8080-name web socket? Yaolin /websocket
You can see that the container is running normally and printing logs, but this way will preempt the terminal. Please use docker start websocket to start:
6.Access (in the physical machine, not in the virtual machine, there seems to be a problem with my spring boot small project here, and 500 errors are reported, but it can be accessed, indicating that the container has run the Spring boot project normally)