File tree Expand file tree Collapse file tree 7 files changed +129
-0
lines changed
main/java/com/levo/dockerexample
test/java/com/levo/dockerexample Expand file tree Collapse file tree 7 files changed +129
-0
lines changed Original file line number Diff line number Diff line change
1
+ bin
2
+ target
3
+ .classpath
4
+ .project
5
+ .settings
6
+ src /main /webapp /META-INF
7
+ .idea
8
+ * .iml
Original file line number Diff line number Diff line change
1
+ # Use an official OpenJDK runtime as a parent image
2
+ FROM openjdk:8-jre-alpine
3
+
4
+ # set shell to bash
5
+ # source: https://stackoverflow.com/a/40944512/3128926
6
+ RUN apk update && apk add bash
7
+
8
+ # Set the working directory to /app
9
+ WORKDIR /app
10
+
11
+ # Copy the fat jar into the container at /app
12
+ COPY /target/docker-java-app-example.jar /app
13
+
14
+ # Make port 8080 available to the world outside this container
15
+ EXPOSE 8080
16
+
17
+ # Run jar file when the container launches
18
+ CMD ["java" , "-jar" , "docker-java-app-example.jar" ]
Original file line number Diff line number Diff line change
1
+
2
+ 1- Maven install to create the fat jar
3
+
4
+ mvn clean install
5
+
6
+ 2- Docker build
7
+
8
+ docker build --tag=docker-java-hello-world-app .
9
+
10
+ 3- Docker run
11
+
12
+ docker run -p 80:8080 docker-java-hello-world-app
13
+
14
+ 4- Test the app
15
+
16
+ http://localhost/docker-java-app/test
17
+
18
+ 5- Get the container id
19
+
20
+ docker container ls
21
+
22
+ 6- Get into the app
23
+
24
+ docker exec -it <container_id> /bin/bash
25
+
26
+ 7- To stop the container
27
+
28
+ docker container stop <container_id>
Original file line number Diff line number Diff line change
1
+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
3
+ <modelVersion >4.0.0</modelVersion >
4
+ <groupId >com.levo.dockerexample</groupId >
5
+ <artifactId >docker-java-app-example</artifactId >
6
+ <packaging >jar</packaging >
7
+ <version >1.0-SNAPSHOT</version >
8
+ <name >docker-java-app-example</name >
9
+ <url >http://maven.apache.org</url >
10
+
11
+ <properties >
12
+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
13
+ <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
14
+ <java .version>1.8</java .version>
15
+ <start-class >com.levo.dockerexample.DockerApp</start-class >
16
+ </properties >
17
+
18
+ <parent >
19
+ <groupId >org.springframework.boot</groupId >
20
+ <artifactId >spring-boot-starter-parent</artifactId >
21
+ <version >2.1.1.RELEASE</version >
22
+ </parent >
23
+
24
+ <dependencies >
25
+ <dependency >
26
+ <groupId >org.springframework.boot</groupId >
27
+ <artifactId >spring-boot-starter-web</artifactId >
28
+ </dependency >
29
+ </dependencies >
30
+
31
+ <build >
32
+ <finalName >docker-java-app-example</finalName >
33
+ <plugins >
34
+ <plugin >
35
+ <groupId >org.springframework.boot</groupId >
36
+ <artifactId >spring-boot-maven-plugin</artifactId >
37
+ </plugin >
38
+ </plugins >
39
+ </build >
40
+
41
+ </project >
Original file line number Diff line number Diff line change
1
+ package com .levo .dockerexample ;
2
+
3
+ import org .springframework .boot .SpringApplication ;
4
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
+
6
+ @ SpringBootApplication
7
+ public class DockerApp {
8
+ public static void main (String [] args ) {
9
+ SpringApplication .run (DockerApp .class , args );
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ package com .levo .dockerexample .controller ;
2
+
3
+ import java .util .Date ;
4
+
5
+ import org .springframework .web .bind .annotation .RequestMapping ;
6
+ import org .springframework .web .bind .annotation .RequestMethod ;
7
+ import org .springframework .web .bind .annotation .RestController ;
8
+
9
+ @ RestController
10
+ @ RequestMapping ("docker-java-app" )
11
+ public class HelloController {
12
+
13
+ @ RequestMapping (value = "/test" , method = RequestMethod .GET )
14
+ public String test () {
15
+ return "docker-java-app is up and running: " + new Date ();
16
+ }
17
+
18
+ }
Original file line number Diff line number Diff line change
1
+ package com .levo .dockerexample ;
2
+
3
+ public class Test {
4
+
5
+ }
You can’t perform that action at this time.
0 commit comments