Skip to content

Instantly share code, notes, and snippets.

@dipspb
Last active January 1, 2024 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dipspb/a08258117f5bbc4fc14712ac2f98f66b to your computer and use it in GitHub Desktop.
Save dipspb/a08258117f5bbc4fc14712ac2f98f66b to your computer and use it in GitHub Desktop.
docker-compose.yml structuring example
version: "3.4"
# Prepare files for this example:
# mkdir -p ./a ./b ./c && touch a/a.txt b/b.txt c/c.txt
x-default-image: &x-default-image
image: ubuntu
x-default-cmd: &x-default-cmd
command: bash -c "echo $${HELLO} $${SVC_NAME} ; ls -al /tmp/*"
# map merge example
x-default-environment: &x-default-environment
HELLO: Hi! I am
SVC_NAME: service-X-DEFAULT
# sequence merge example, there are no "- " prefixes
x-default-volumes: &x-default-volumes |-
./a:/tmp/A
./b:/tmp/B
services:
service-A:
<<:
- *x-default-image
- *x-default-cmd
profiles:
- a
- both
environment:
# map merge example
<<: *x-default-environment
SVC_NAME: service-A
volumes:
# sequence merge example
- *x-default-volumes
service-B:
<<: [*x-default-image, *x-default-cmd]
profiles:
- b
- both
environment:
<<: *x-default-environment
SVC_NAME: service-B
volumes:
# sequence merge example
- *x-default-volumes
depends_on:
service-A:
condition: service_completed_successfully
links:
- service-A
service-C:
<<: [*x-default-image, *x-default-cmd]
profiles:
- a
- c
environment:
<<: *x-default-environment
SVC_NAME: service-C
volumes:
# sequence merge example
- *x-default-volumes
- ./c:/tmp/C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment