Example : I would like to terminate node
and filebeat
service after test
service run finished or exit code is zero (success).
We need to create shell script and adding two docker-compose up
's options,
it's --abort-on-container-exit
and --exit-code-from
(the shell script below related with docker-container.yml
)
shell-scrip.sh
( (docker-compose -f docker-compose.yml down -v) || : ) && \
docker-compose -f docker-compose.yml up --build \
--abort-on-container-exit \
--exit-code-from test && \
docker-compose -f docker-compose.yml down -v
docker-container.yml
version: '3'
services:
node:
build:
context: ./
dockerfile: Dockerfile
depends_on:
- filebeat
ports:
- '8002:8002'
command: bash /build-script/run-local.sh
filebeat:
image: docker.elastic.co/beats/filebeat:7.5.0
volumes:
- ./ag/logs:/logs
command: bash -c "(chmod go-w /logs/filebeat.yml) && (bash /logs/start.sh)"
test:
build:
context: .
dockerfile: Dockerfile
depends_on:
- node
command: /bin/sh something.sh
networks:
default:
driver: bridge