Move all samples to the root dir
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
This commit is contained in:
62
sparkjava/README.md
Normal file
62
sparkjava/README.md
Normal file
@@ -0,0 +1,62 @@
|
||||
## Compose sample application
|
||||
### Spark Java
|
||||
|
||||
Project structure:
|
||||
```
|
||||
.
|
||||
├── docker-compose.yaml
|
||||
├── README.md
|
||||
└── sparkjava
|
||||
├── Dockerfile
|
||||
└── ...
|
||||
```
|
||||
|
||||
[_docker-compose.yaml_](docker-compose.yaml)
|
||||
```
|
||||
version: "3.7"
|
||||
services:
|
||||
sparkjava:
|
||||
build: sparkjava
|
||||
ports:
|
||||
- 80:8080
|
||||
```
|
||||
The compose file defines an application with one service `sparkjava`.
|
||||
When deploying the application, docker-compose maps port 8080 of the sparkjava service container to port 80 of the host as specified in the file.
|
||||
Make sure port 80 on the host is not already being in use.
|
||||
|
||||
## Deploy with docker-compose
|
||||
|
||||
```
|
||||
$ docker-compose up -d
|
||||
Creating network "sparkjava_default" with the default driver
|
||||
Building sparkjava
|
||||
Step 1/9 : FROM maven:3.5-jdk-8-alpine AS build
|
||||
3.5-jdk-8-alpine: Pulling from library/maven
|
||||
...
|
||||
Successfully tagged sparkjava_sparkjava:latest
|
||||
WARNING: Image for service sparkjava was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
|
||||
Creating sparkjava_sparkjava_1 ... done
|
||||
```
|
||||
|
||||
## Expected result
|
||||
|
||||
Listing containers must show two containers running and the port mapping as below:
|
||||
```
|
||||
$ docker ps
|
||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||
5af94cb25394 sparkjava_sparkjava "/bin/sh -c 'java -j…" 20 seconds ago Up 19 seconds 0.0.0.0:80->8080/tcp sparkjava_sparkjava_1
|
||||
```
|
||||
|
||||
After the application starts, navigate to `http://localhost:80` in your web browser or run:
|
||||
```
|
||||
$ curl localhost:80
|
||||
Hello world
|
||||
```
|
||||
|
||||
Stop and remove the containers
|
||||
```
|
||||
$ docker-compose down
|
||||
Stopping sparkjava_sparkjava_1 ... done
|
||||
Removing sparkjava_sparkjava_1 ... done
|
||||
Removing network sparkjava_default
|
||||
```
|
6
sparkjava/docker-compose.yaml
Normal file
6
sparkjava/docker-compose.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
version: "3.7"
|
||||
services:
|
||||
sparkjava:
|
||||
build: sparkjava
|
||||
ports:
|
||||
- 80:8080
|
10
sparkjava/sparkjava/Dockerfile
Executable file
10
sparkjava/sparkjava/Dockerfile
Executable file
@@ -0,0 +1,10 @@
|
||||
FROM maven:3.5-jdk-8-alpine AS build
|
||||
COPY pom.xml .
|
||||
RUN mvn --batch-mode dependency:resolve
|
||||
COPY src/ src
|
||||
RUN mvn --batch-mode clean compile assembly:single
|
||||
|
||||
FROM openjdk:8-jre-alpine3.7
|
||||
EXPOSE 8080
|
||||
COPY --from=build target/app.jar /app.jar
|
||||
CMD java -jar /app.jar
|
48
sparkjava/sparkjava/pom.xml
Executable file
48
sparkjava/sparkjava/pom.xml
Executable file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.company</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>App</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
<finalName>app</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sparkjava</groupId>
|
||||
<artifactId>spark-core</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
9
sparkjava/sparkjava/src/main/java/App.java
Executable file
9
sparkjava/sparkjava/src/main/java/App.java
Executable file
@@ -0,0 +1,9 @@
|
||||
import static spark.Spark.*;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
port(8080);
|
||||
|
||||
get("/", (req, res) -> "Hello world");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user