2020-03-06 18:25:16 +00:00
## Compose sample application
### Spark Java
Project structure:
```
.
2022-05-10 09:59:25 +00:00
├── compose.yaml
2020-03-06 18:25:16 +00:00
├── README.md
└── sparkjava
├── Dockerfile
└── ...
```
2022-05-10 09:59:25 +00:00
[_compose.yaml_ ](compose.yaml )
2020-03-06 18:25:16 +00:00
```
services:
sparkjava:
build: sparkjava
ports:
2020-03-17 14:30:49 +00:00
- 8080:8080
2020-03-06 18:25:16 +00:00
```
The compose file defines an application with one service `sparkjava` .
2022-05-10 09:59:25 +00:00
When deploying the application, docker compose maps port 8080 of the sparkjava service container to port 8080 of the host as specified in the file.
2020-03-17 14:30:49 +00:00
Make sure port 8080 on the host is not already being in use.
2020-03-06 18:25:16 +00:00
2022-05-10 09:59:25 +00:00
## Deploy with docker compose
2020-03-06 18:25:16 +00:00
```
2022-05-10 09:59:25 +00:00
$ docker compose up -d
2020-03-06 18:25:16 +00:00
Creating network "sparkjava_default" with the default driver
Building sparkjava
2020-03-17 14:30:49 +00:00
Step 1/11 : FROM maven:3.6.3-jdk-11 AS build
3.6.3-jdk-11: Pulling from library/maven
2020-03-06 18:25:16 +00:00
...
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
2020-07-28 03:22:17 +00:00
Listing containers must show one container running and the port mapping as below:
2020-03-06 18:25:16 +00:00
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2020-03-17 14:30:49 +00:00
5af94cb25394 sparkjava_sparkjava "/bin/sh -c 'java -j…" 20 seconds ago Up 19 seconds 0.0.0.0:8080->8080/tcp sparkjava_sparkjava_1
2020-03-06 18:25:16 +00:00
```
2020-03-17 14:30:49 +00:00
After the application starts, navigate to `http://localhost:8080` in your web browser or run:
2020-03-06 18:25:16 +00:00
```
2020-03-17 14:30:49 +00:00
$ curl localhost:8080
Hello from Docker!
2020-03-06 18:25:16 +00:00
```
Stop and remove the containers
```
2022-05-10 09:59:25 +00:00
$ docker compose down
2020-03-06 18:25:16 +00:00
Stopping sparkjava_sparkjava_1 ... done
Removing sparkjava_sparkjava_1 ... done
Removing network sparkjava_default
```
2022-07-12 10:22:52 +00:00
## Use with Docker Development Environments
You can use this sample with the Dev Environments feature of Docker Desktop.
To develop directly sparkjava service inside containers, you just need to use the https git url of the sample:
`https://github.com/docker/awesome-compose/tree/master/sparkjava`
![page ](../dev-envs.png )