docker compose execute command before stop code example
Example 1: docker compose run
docker-compose up --build -d --remove-orphans
docker-compose -f docker-compose.yml up --build -d --remove-orphans
Example 2: docker-compose restart one container
It is very simple: Use the command:
docker-compose restart worker
You can set the time to wait for stop before killing the container (in seconds)
docker-compose restart -t 30 worker
Note that this will restart the container but without rebuilding it. If you want to apply your changes and then restart, take a look at the other answers.