docker-compose not sending signals to trap

Viewed 107

I have a simple docker-compose.yml

version: '3.8'
services:
  port-forwarder:
    image: test
    container_name: port-forwarder
    volumes:
      - "/path_to_scripts/port_forwarder.sh:/port_forwarder.sh"
    command: "/port_forwarder.sh"

port_forwarder.sh

#!/usr/bin/env bash
trap 'echo exiting ; exit 0' SIGTERM TERM SIGINT INT EXIT WINCH SIGWINCH
tail -f /dev/null

Dockerfile

FROM alpine:3.12.0
RUN apk add --no-cache bash

If I build the image and run it using

docker build -t test .
docker run --name test -it --rm -v /path_to_scripts/port_forwarder.sh:/port_forwarder.sh test /port_forwarder.sh

and then hit ctrl-c, it catches the SIGTERM and writes "exiting" on the console. But when I run it using 'docker-compose up' and hit ctrl-c it hangs and is killed after 10 seconds. I am using docker on OSX. What could be the reason and how can I catch the termination signal from docker-compose?

0 Answers
Related