English | 한국어
Docker Boot provides seamless integration between Docker containers and Spring Boot applications. It allows you to manage Docker container lifecycles through Spring configuration and programmatic controls.
- Features
- Getting Started
- Configuration
- Event System
- Comparison with Spring Boot Docker Compose
- API Reference
- Contributing
- License
-
Spring Native Integration
- Spring Boot auto-configuration
- YAML/Properties based configuration
- Spring profiles support
- Spring events integration
-
Container Lifecycle Management
- Three lifecycle modes (START_AND_STOP, START_ONLY, NONE)
- Automatic container cleanup
- Event-driven control
- Graceful shutdown handling
-
Docker Features Support
- Port mapping
- Volume mounting
- Environment variables
- Health checks
- Resource constraints
- Custom networks
- Container labels
-
Development Support
- Multi-container management
- Development/Production profiles
- Detailed logging
- Error handling
- Java 17 or higher
- Spring Boot 3.0 or higher
- Docker Engine installed and running
<dependency>
<groupId>io.github.ddaakk</groupId>
<artifactId>docker-container-spring-boot-starter</artifactId>
<version>0.2.0</version>
</dependency>
implementation 'io.github.ddaakk:docker-container-spring-boot-starter:0.2.0'
- Add the dependency to your project
- Configure containers in
application.yml
:
docker:
containers:
redis:
enabled: true
container-name: my-redis
image-name: redis:latest
lifecycle-mode: START_AND_STOP
ports:
6379: 6379
- Run your Spring Boot application
docker:
host: unix:///var/run/docker.sock
tls-verify: false
registry:
url: https://index.docker.io/v1/
username: username
password: password
docker:
containers:
service-name: # Service identifier
enabled: true # Enable/disable container
container-name: my-container # Container name
image-name: image:tag # Docker image
lifecycle-mode: START_AND_STOP # Lifecycle mode
docker:
containers:
service-name:
# Basic Settings
enabled: true
container-name: my-container
image-name: image:tag
lifecycle-mode: START_AND_STOP
# Network
ports:
8080: 8080
networks:
- network-name
dns:
- 8.8.8.8
# Resources
memory: 512M
cpu-shares: 1024
# Storage
volumes:
/host/path: /container/path
tmpfs:
- /tmp
# Environment
environment:
KEY: value
env-file:
- ./env.list
# Runtime
command: ["custom", "command"]
entrypoint: ["custom", "entrypoint"]
working-dir: /app
# Health & Monitoring
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost"]
interval: 30s
timeout: 10s
retries: 3
# Additional Settings
labels:
app: service-name
restart-policy:
name: on-failure
max-retry: 3
Docker Boot provides three lifecycle modes for container management:
- Starts with Spring Boot application
- Stops and removes on shutdown
- Best for development and testing
lifecycle-mode: START_AND_STOP
- Starts with Spring Boot application
- Continues running after shutdown
- Good for shared services
lifecycle-mode: START_ONLY
- No automatic management
- Manual control only
- For pre-existing containers
lifecycle-mode: NONE
docker:
containers:
postgres:
enabled: true
container-name: postgres-dev
image-name: postgres:14
lifecycle-mode: START_AND_STOP
ports:
5432: 5432
environment:
POSTGRES_DB: devdb
POSTGRES_USER: dev
POSTGRES_PASSWORD: devpass
volumes:
postgres-data: /var/lib/postgresql/data
docker:
containers:
redis:
enabled: true
container-name: redis-prod
image-name: redis:7
lifecycle-mode: START_ONLY
ports:
6379: 6379
memory: 1G
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
public enum Action {
START, // Create and start container
STOP, // Stop container
REMOVE // Remove container
}
@Service
public class DockerService {
private final ApplicationEventPublisher eventPublisher;
public void startContainer() {
eventPublisher.publishEvent(
new DockerContainerEvent(this, DockerContainerEvent.Action.START)
);
}
}
@Service
public class ContainerManager {
@EventListener
public void handleDockerEvent(DockerContainerEvent event) {
switch (event.getAction()) {
case START -> startContainer();
case STOP -> stopContainer();
case REMOVE -> removeContainer();
}
}
}
Feature | Docker Boot | Spring Boot Docker Compose |
---|---|---|
Configuration | Spring YAML/Properties | docker-compose.yml |
Container Control | Programmatic + Events | File-based |
Spring Integration | Native integration | Basic integration |
Lifecycle Modes | Three modes | Three modes |
Development Focus | Both dev and prod | Development focused |
- Need programmatic container control
- Want Spring-native configuration
- Require event-based management
- Need fine-grained lifecycle control
public interface DockerContainerManager {
String createAndStart();
void stop(String containerId);
void remove(String containerId);
}
public class DockerContainerEvent extends ApplicationEvent {
public enum Action {
START, STOP, REMOVE
}
}
We welcome contributions! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- Clone the repository
- Install dependencies
- Run tests
- Submit changes
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
ddaakk - GitHub
© 2024 Docker Boot. All rights reserved.