In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to develop Java 8 Spring Boot applications in Docker". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to develop Java 8 Spring Boot applications in Docker" can help you solve the problem.
First, let's examine the docker-compose file:
Version: '2'services: springappserver: build: context:. Dockerfile: springapp.dockerfile ports:-"8080 net-spring-db volumes: -.: / vol/development depends_on:-mysqldbserver mysqldbserver: build: context:. Dockerfile: mysqldb.dockerfile ports:-"3306 net-spring-db 3306" networks:-net-spring-db environment: mysql_database: testdb mysql_user: myuser mysql_password: mypassword mysql_root_password: myrootpassword container_name: mysqldbservernetworks: net-spring-db: driver: bridge
We have two servers each on net-spring-db'. The first one is named 'springappserver', and configured with springapp.dockerfile. The second one is named mysqldbserver and configured using mysqldb.dockerfile.
Now, let's take a look at springapp.dockerfile:
# # java 1.8 & maven dockerfile### pull base image.from java:8# maintainermaintainer dursunkoc "dursunkoc@gmail.com" # update packages and install mavenrun\ export debian_frontend=noninteractive & &\ sed-I's multiverse$ # (. * multiverse$\) /\ 1Universe g'/ etc/apt/sources.list & &\ apt-get update & &\ apt-get-y upgrade & &\ apt-get install-y vim wget curl maven# attach volumesvolume / vol/development# create working directoryrun mkdir -p / vol/developmentworkdir / vol/development# maven execcmd ["mvn" "clean", "package", "exec:java"]
The docker file configures the docker image, which inherits from the java 8 image of docker hub. On the java 8 image, I installed vim,wget,curl,maven and set up the volume to place my existing project code. Finally, execute the maven command to run my application.
Now let's check the mysqldb.dockerfile:
From mysql/mysql-servermaintainer dursun koc # copy the database initialize script: # contents of / docker-entrypoint-initdb.d are run on mysqld startupadd mysql/ / docker-entrypoint-initdb.d/
The docker file configures the docker mirror, which inherits from the mysql / mysql-server image of docker hub. On the mysql image, I placed my db-schema creation scripts, which are located in the mysql folder. I have a sql file-data.sql-in this folder to create the 'person' table.
Now, let's look at the application structure.
Our application starts with the src / com / turkcell / softlab / application.java file, and our only controller is personcontroller (src / com / turkcell / softlab / controller / personcontroller.java).
You can run the entire project with a simple command:
Docker-compose up-d
When testing, use the following two commands on the local computer:
Create a new person:
Curl-h "content-type:application / json"-x post-d "{\" first\ ":\" mustafa\ ",\" last\ ":\" ko ç\ ",\" dateofbirth\ "381110400000," placeofbirth ":\" erzincan\ "}" http://192.168.99.100 http://192.168.99.100 8080max people "
List the existing people in the database:
Curl-h "content-type:application / json"-x get "http://192.168.99.100:8080/people" on how to develop Java 8 Spring Boot applications in Docker" ends here. Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.