Options: -f, --force Don't ask to confirm removal -s, --stop Stop the containers, if required, before removing -v Remove any anonymous volumes attached to containers
$ docker-compose ps -a Name Command State Ports ----------------------------------------------------------------------------------------- demo_demo_run_368b1fe0df5f /docker-entrypoint.sh whoami Exit 0 demo_demo_run_9c4367d358bd /docker-entrypoint.sh ls / ... Exit 0 nginx1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp $ docker-compose rm Going to remove demo_demo_run_368b1fe0df5f, demo_demo_run_9c4367d358bd Are you sure? [yN] y Removing demo_demo_run_368b1fe0df5f ... done Removing demo_demo_run_9c4367d358bd ... done $ docker-compose ps -a Name Command State Ports -------------------------------------------------------------------- nginx1 /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp
$ docker-compose rm -f No stopped containers $ docker-compose rm -s Stopping nginx1 ... done Going to remove nginx1 Are you sure? [yN] # -sf 强制删除所有服务容器,包括正在运行的服务 $ docker-compose rm -sf Going to remove nginx1 Removing nginx1 ... done $ docker-compose ps -a Name Command State Ports ------------------------------