How can i run a script before destroy a docker container?

I need the run a shell script before destroy a docker container.But this script should not work when this container stopped.Only run when i destroy and rm this container.How can i do this?

  • docker.io command replaced just 'docker'
  • Type “geometry” does not exists [duplicate]
  • Xvfb command in docker supervisor conf not working
  • Dockerizing Spring Boot App with Postgresql
  • Mesosphere local development
  • Is it possible to create a docker container that contains one or more containers? [closed]
  • Docker: disable pulling from remote registry
  • Docker-Compose Up Works but Eb Local Run does not
  • Which Docker base image should be used to install Apps in a container without any additional OS?
  • Elastic search with docker does not start
  • Docker compose with networks and “internal” property example
  • docker run does not work from cronjob
  • 2 Solutions collect form web for “How can i run a script before destroy a docker container?”

    It’s not currently possible. Have a look at this issue for more information: https://github.com/docker/docker/issues/6982

    Since it is not possible at the moment, you could use a workaround:

    alias "docker-destroy"="<run-script> && docker rm"
    

    For example:

    alias "docker-destroy"="echo 'test' && docker rm"
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.