Skip to Content
杂项环境安装Docker

一键安装 Docker

curl -fsSL https://get.docker.com | bash # 改用国内镜像 # curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

Docker Image Prune

删除所有悬挂的镜像(dangling images),可以使用以下命令:

docker image prune

删除所有未被使用的镜像,可以使用以下命令:

docker image prune -a #WARNING! This will remove all images without at least one container associated to them. #Are you sure you want to continue? [y/N] y

Docker System Prune

删除所有未被使用的对象,可以使用以下命令:

docker system prune

默认情况下将删除:

  • Stopped containers – 所有已停止的容器
  • Networks that are not being used by at least one container - 所有未被容器使用的网络
  • Dangling images - 所有悬挂的镜像
  • Dangling build cache - 所有悬挂的构建缓存
docker system prune -a # WARNING! This will remove: # - all stopped containers # - all networks not used by at least one container # - all images without at least one container associated to them # - all build cache # Are you sure you want to continue? [y/N]

Update Docker images

如果你希望自动拉取并重启容器来完成镜像更新,可以使用 watchtower 

快速启动

docker run -d \ --name watchtower \ --restart unless-stopped \ -v /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtower \ --cleanup \ --interval 300
  • --interval 300:每 300 秒检查一次更新
  • --cleanup:更新完成后清理旧镜像

仅更新指定容器

docker run -d \ --name watchtower \ --restart unless-stopped \ -v /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtower \ --cleanup \ nginx app

手动执行一次更新

docker run --rm \ -v /var/run/docker.sock:/var/run/docker.sock \ containrrr/watchtower \ --run-once

Docker Compose 示例

services: watchtower: image: containrrr/watchtower container_name: watchtower restart: unless-stopped volumes: - /var/run/docker.sock:/var/run/docker.sock command: --cleanup --interval 300
Last updated on