如何删除未运行的Docker容器?

时间:2019-01-20 02:55:05

标签: docker

是否可以删除未运行的容器?

我知道例如这将从创建的图像中删除容器

   getCommunity: async (req, res, next) => {

        const { playerId } = req.params;
        const newCommunity = new Community(req.body);
        //Get Player
        const player = Player.findById(playerId);
        // Assign player as a part of community's player
        newCommunity.communityPlayer.push(player); // here change your code like this
        // Save the community
        await newCommunity.save();
        // Add community to the player's array
        player.PlayerCommunities.push(newCommunity);
        // Save the playerCommunities
        await player.save();
        res.status(201).json(newCommunity)
    }

但是我想知道如何删除未运行的那些

1 个答案:

答案 0 :(得分:2)

使用docker container prune命令,它将删除所有停止的容器。您可以在以下官方文档中了解有关此命令的更多信息:https://docs.docker.com/engine/reference/commandline/container_prune/

类似地,Docker具有用于docker network prunedocker image prunedocker volume prune的命令以修剪网络,映像和卷。

我大多数时候都使用docker system prune,它会清理未使用的容器,以及网络和晃来晃去的图像。

如果要使用系统组件清理卷,请使用docker system prune --volumes。在这种情况下,未使用的卷也将被删除,因此请小心,您可能会丢失数据。

相关问题