TLDR: ainda não é possível 2018-11 ; use docker-compose down
ou docker-compose run --rm
Eu quero dar uma resposta atualizada a esta pergunta porque são quase 3 anos depois. Isso irá proteger os outros de alguma pesquisa por conta própria.
Eu tive a mesma pergunta e aqui estão as soluções que encontrei (incluindo a da própria pergunta):
docker-compose down
que faz o seguinte:
Stops containers and removes containers, networks, volumes, and images created by up.
By default, the only things removed are:
- Containers for services defined in the Compose file - Networks defined in the networks section of the Compose file - The default network, if one is used
Networks and volumes defined as external are never removed.
Embora não seja possível declará-lo em docker-compose.yml
, você poderá evitar problemas; especialmente com volumes e redes.
docker-compose run --rm
--rm - Remove container after run. Ignored in detached mode.
Runs a one-time command against a service. For example, the following command starts the web service and runs bash as its command.
docker-compose run web bash
[...] the command passed by run overrides the command defined in the service configuration.
[...] the command does not create any of the ports specified in the service configuration. This prevents port collisions with already-open ports. If you do want the service’s ports to be created and mapped to the host, specify the --service-ports flag
docker-compose rm -f
-f, --force Don't ask to confirm removal