breaking down the docker compose
breaking down the docker compose
compose
1. Version: '3'
This specifies the version of the Docker Compose file format. In this case,
version 3 is used, which is compatible with Docker Engine 1.13.0 and above.
2. Services
The services section defines all the containers you want to run. In this example,
there are two
Service: app
application. You can either use a locally built image (via docker build ) or pull an
image from a Docker registry (like Docker Hub).
Example: You could build your Spring Boot app image and tag it as your-
inside the container. This allows you to access your Spring Boot app by
navigating to http://localhost:8080 in your browser.
depends_on: - db : This ensures that the app service (Spring Boot app) starts
only after the db service (PostgreSQL) is up and running. This ensures that
the database is available before the app starts.
the custom network my-network . This allows the app and db services to
communicate with each other.
Service: db
image: postgres:17 : This specifies the Docker image to use for the PostgreSQL
database container. In this case, it's using the official postgres image, version
17.
3. Networks
: This defines a custom network called my-network . Both the app and db
my-network
services are connected to this network, allowing them to communicate with each
other using the service names ( app and db ) as hostnames.
4. Volumes
Docker volumes are used to persist data outside the lifecycle of a container. The
Networking: The custom network ( my-network ) ensures that the two services
can resolve each other's hostnames ( app and db ) and communicate internally.
💡 Summary
Services: Defines two containers: one for the Spring Boot
application and one for PostgreSQL.
Ports: Maps port 8080 of the host to port 8080 of the Spring Boot
app container, enabling access via localhost:8080 .