Docker Compose
Docker Compose is a tool that allows you to define and manage multi-container applications. It uses a YAML file to define the services, networks, and volumes for your application's containers.
With Docker Compose, you can specify the configuration for each service in your application, including the Dockerfile, environment variables, ports mapping, and dependencies between services.
Docker Compose makes it easy to manage the lifecycle of your application's containers. You can use it to start, stop, and restart your application, as well as scale your services.
Here's an example Docker Compose file for a Java microservice application with a PostgreSQL database:
SNIPPET
1version: '3'
2services:
3 app:
4 build:
5 context: .
6 dockerfile: Dockerfile
7 ports:
8 - '8080:8080'
9 depends_on:
10 - db
11 db:
12 image: postgres
13 environment:
14 - POSTGRES_USER=postgres
15 - POSTGRES_PASSWORD=secret
xxxxxxxxxx
15
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- '8080:8080'
depends_on:
- db
db:
image: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=secret
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment