"If you want to remove the container after running while overriding the container’s restart policy, use the --rm flag:
$ docker compose run --rm web python manage.py db upgrade
This runs a database upgrade script, and removes the container when finished running, even if a restart policy is specified in the service configuration."
maybe instructions at https://docs.docker.com/engine/reference/commandline/compose_run/ are most relevant
"If you want to remove the container after running while overriding the container’s restart policy, use the --rm flag:
This runs a database upgrade script, and removes the container when finished running, even if a restart policy is specified in the service configuration."
but also see