services:
mys-backend:
restart: always
build: .
container_name: mys-backend
ports:
- '9095:8080'
links:
- 'mys-database:database'
depends_on:
- mys-database
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${DB_NAME}
- SPRING_DATASOURCE_USERNAME=${POSTGRES_USER}
- SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD}
mys-database:
ports:
- '5432:5432'
image: postgres:12-alpine
container_name: mys-database
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- ./postgres-data:/var/lib/postgresql/data
I put all the values in the application.properties
hoping that these values would be pulled up when I am running the docker compose up
command but to no avail
You can use an
.env
file and set variables like:and pass it to your Docker image:
Check Docker docs