docker-compose for services
📖 Scenario: You are building a simple Spring Boot application that needs to run alongside a database service. To make it easy to start both services together, you will use docker-compose to define and run these services.
🎯 Goal: Create a docker-compose.yml file that defines two services: a Spring Boot app and a PostgreSQL database. The Spring Boot app should connect to the database service using the correct hostname and port.
📋 What You'll Learn
Define a service named
app using the Spring Boot Docker image springboot-app:latestDefine a service named
db using the official PostgreSQL image postgres:15Set environment variables for the
db service: POSTGRES_USER as user, POSTGRES_PASSWORD as password, and POSTGRES_DB as mydbExpose port
5432 on the db serviceConfigure the
app service to depend on dbSet environment variables for the
app service to connect to the database host db and port 5432💡 Why This Matters
🌍 Real World
Docker Compose is widely used to run multi-service applications locally or in development environments. It simplifies starting and stopping related services together.
💼 Career
Understanding docker-compose is essential for developers and DevOps engineers to manage containerized applications efficiently, especially when working with microservices or databases.
Progress0 / 4 steps