An open API service indexing awesome lists of open source software.

https://github.com/kh77/hello-world-docker

Docker example in Spring Boot
https://github.com/kh77/hello-world-docker

docker java spring-boot

Last synced: about 2 months ago
JSON representation

Docker example in Spring Boot

Awesome Lists containing this project

README

          

# Hello World Rest API

### Building an Image

1. Build a Jar - /target/hello-world-docker.jar
2. Setup the Prerequisites for Running the JAR - openjdk:8-jdk-alpine
3. Copy the jar
4. Run the jar

### Docker Commands - Creating Image Manually

- docker run -dit openjdk:8-jdk-alpine
- docker container exec naughty_knuth ls /tmp
- docker container cp target/hello-world-docker.jar naughty_knuth:/tmp
- docker container exec naughty_knuth ls /tmp
- docker container commit naughty_knuth kh77/hello-world-docker:manual1
- docker run kh77/hello-world-docker:manual1
- docker container ls
- docker container commit --change='CMD ["java","-jar","/tmp/hello-world-docker.jar"]' naughty_knuth kh77/hello-world-docker:manual2
- docker run -p 8080:8080 kh77/hello-world-docker:manual2

### Running the Application

Run RestfulWebServicesApplication as a Java Application.

- http://localhost:8080/hello-world

```txt
Hello World
```

- http://localhost:8080/hello-world-bean

```json
{"message":"Hello World"}
```

- http://localhost:8080/hello-world/path-variable/kh77

```json
{"message":"Hello World, practice"}
```

## Docker File

### Basic
```
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ADD target/hello-world-docker.jar hello-world-docker.jar
ENTRYPOINT ["sh", "-c", "java -jar /hello-world-docker.jar"]
```

### Level 2

```
FROM openjdk:8-jdk-alpine
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","RestfulWebServicesApplication"]
```

## Plugins

### Dockerfile Maven

- From Spotify
- https://github.com/spotify/dockerfile-maven

```

com.spotify
dockerfile-maven-plugin
1.4.10


default

build




kh77/${project.name}
${project.version}
true

```

docker build -t kh77/hello-world-docker:dockerfile1 .

for jib kazim
Containerizing application to Docker daemon as 01-hello-world-docker:0.0.1-SNAPSHOT...

### JIB

- https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin#quickstart

- https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md

#### "useCurrentTimestamp - true" discussion
- https://github.com/GooleContainerTools/jib/blob/master/docs/faq.md#why-is-my-image-created-48-years-ago
- https://github.com/GoogleContainerTools/jib/issues/413

```

com.google.cloud.tools
jib-maven-plugin
1.6.1


USE_CURRENT_TIMESTAMP




package

dockerBuild


```
```


openjdk:alpine


kh77/${project.name}

${project.version}
latest




-Xms512m

RestfulWebServicesApplication

8100

```

### fabric8io/docker-maven-plugin

- https://dmp.fabric8.io/
- Remove Spotify Maven and JIB Plugins. Add the plugin shown below and configure property for jar file.

Supports
- Dockerfile
- Defining Dockerfile contents in POM XML.

#### Using Dockerfile

```

io.fabric8
docker-maven-plugin
0.26.0


docker-build
package

build


```

```

...
${project.build.directory}/${project.build.finalName}.jar

```

#### Using XML Configuration

```

io.fabric8
docker-maven-plugin
0.26.0
true

true


${project.artifactId}

java:8-jdk-alpine


java
-jar
/maven/${project.build.finalName}.jar



artifact







docker-build
package

build


```

### Maven Dependency Plugin

```

org.apache.maven.plugins
maven-dependency-plugin


unpack
package

unpack




${project.groupId}
${project.artifactId}
${project.version}




```

### Improve Caching of Images using Layers

#### CURRENT SITUATION

---------------
FAT JAR
---------------
JDK
---------------

#### DESIRED SITUATION
---------------
CLASSES
---------------
DEPENDENCIES
---------------
JDK
---------------