https://github.com/tranphuquy19/springboot-docker
Spring boot - Docker Multi-Stage build
https://github.com/tranphuquy19/springboot-docker
docker docker-compose spring-boot
Last synced: 2 months ago
JSON representation
Spring boot - Docker Multi-Stage build
- Host: GitHub
- URL: https://github.com/tranphuquy19/springboot-docker
- Owner: tranphuquy19
- Created: 2022-07-23T02:59:33.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-24T18:04:11.000Z (almost 3 years ago)
- Last Synced: 2025-01-13T02:13:46.910Z (4 months ago)
- Topics: docker, docker-compose, spring-boot
- Language: Java
- Homepage:
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring boot - Docker Multi-Stage build
- [What is a multi-stage build?](https://vsupalov.com/docker-multi-stage-advantages/)
- [Official documentation](https://spring.io/guides/topicals/spring-boot-docker/)_Note: To reduce build time please enable DOCKER_BUILDKIT=1_
```bash
export DOCKER_BUILDKIT=1 # enable Docker buildkit (for Linux)
```## Usage
### Using docker compose
1. Build app image
```bash
docker-compose -f docker-compose.prod.yml build demo
```2. Start app
```bash
docker-compose -f docker-compose.prod.yml up -d
# This command will start only postgres and demo app containers
```If you want to start pgadmin too, you can use the following command:
```bash
docker-compose -f docker-compose.prod.yml --profile debug up -d
# This command will start all containers with debug profile [postgres, demo] + pgadmin4
```3. Stop app
```bash
docker-compose -f docker-compose.prod.yml stop
```4. Destroy app
```bash
docker-compose -f docker-compose.prod.yml down -v --remove-orphans
# This will remove all containers and volumes (lost data)
```5. Start postgres db and pgadmin4 for development
Notice: Please modify the connection string in application.properties file (from `jdbc:postgresql://postgres:5432/demo` -> `jdbc:postgresql://localhost:5432/demo`).
```bash
docker-compose -f docker-compose.dev.yml up -d
# This command will start postgres and pgadmin4 with the ports exposed on host machine
```### Using docker CLI
1. Build image
```bash
docker build -t demo:latest .
```2. Build builder image
```bash
docker build --target builder -t demo:builder .
```3. Run image
```bash
docker run -p 8080:8080 demo:latest
```