In this article, I will show you how to develop and run a simple Spring web application using Java 8 without having Java 8 installed on your local machine. Python developers use virtual environments to create and manage separate environments for different projects, each using a different version of Python to execute, store, and resolve Python dependencies. Java and many other technologies do not support the virtual environment concept. At this point, Docker comes to our aid. Docker is a virtualization platform. You can find basic information and installation guides from the official Docker website. Once you have the Docker Toolbox installed, you do not need to install Java 8 or MySQL which are required in our sample applications. First, let's check version : '2' services: springappserver: build: context: . dockerfile: springapp.dockerfile ports: - "8080:8080" networks: - net-spring-db volumes: - .:/vol/development depends_on: -mysqldbserver mysqldbserver: build: context: . dockerfile: mysqldb.dockerfile ports: - "3306:3306" networks: - net-spring-db environment: MYSQL_DATABASE: testdb MYSQL_USER: myuser MYSQL_PASSWORD: mypassword MYSQL_ROOT_PASSWORD: myrootpassword container_name: mysqldbserver networks: net-spring-db: driver: bridge We have two servers each on 'net-spring-db'. The first is called 'springappserver' and is configured using Now, let’s take a look at the springapp.dockerfile: # # Java 1.8 & Maven Dockerfile # # # pull base image. FROM java:8 # maintainer MAINTAINER Dursun KOC "[email protected]" # update packages and install maven RUN \ export DEBIAN_FRONTEND=noninteractive && \ sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \ apt-get update && \ apt-get -y upgrade && \ apt-get install -y vim wget curl maven # attach volumes VOLUME /vol/development # create working directory RUN mkdir -p /vol/development WORKDIR /vol/development # maven exec CMD ["mvn", "clean", "package", "exec:java"] The Docker file configures a Docker image that inherits from the Java 8 image from Docker Hub. On the Java 8 image, I installed vim, wget, curl, Maven, and set up volumes to house my existing project code. Finally, I execute the Maven command to run my application. Now let's check the mysqldb.dockerfile: FROM mysql/mysql-server MAINTAINER Dursun KOC <[email protected]> # Copy the database initialize script: # Contents of /docker-entrypoint-initdb.d are run on mysqld startup ADD mysql/<yyyy-MM-dd> /docker-entrypoint-initdb.d/ The Docker file configures a Docker image that inherits from the MySQL/mysql-server image from Docker Hub. On the MySQL image I placed my db-schema creation scripts, they are in the MySQL folder. I have a SQL file in this folder - data.sql - to create the 'person' table. Now, let's look at the application structure. Our application is started in the You can run the entire project with a simple command: To test, use the following two commands on your 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:8080/people" • List existing people in the database: curl -H "Content-Type: application/json" -X GET "http://192.168.99.100:8080/people" Summarize The above is the method I introduced to you for developing Java 8 Spring Boot applications in Docker. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: JS implements sliding up and down on the mobile terminal one screen at a time
>>: MySQL binlog opening steps
Due to the initial partitioning of the system, th...
To achieve an effect similar to Windows forms, dr...
This article shares with you the specific method ...
This article describes the steps to install the p...
What does Ctrl+c, Ctrl+d, Ctrl+z mean in Linux? C...
This article shares with you the MySQL 8.0.13 ins...
Today, I encountered a little problem when I was ...
This article example shares the specific code of ...
This article shares the specific code for WeChat ...
Table of contents 1. Characteristics of JS 1.1 Mu...
Table of contents JavaScript private class fields...
Solution process: Method 1: The default kernel ve...
Overview The cloud platform customer's server...
SQLyog connects to mysql error number 1129: mysql...
Preface I am used to writing less/sass, but now I...