欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

docker prune命令定時(shí)清理不常用數(shù)據(jù)的操作方法

 更新時(shí)間:2022年10月18日 09:50:59   作者:海_納百川  
使用docker引擎服務(wù)時(shí)間久了,會(huì)發(fā)現(xiàn)磁盤空間越來越大,現(xiàn)在要?jiǎng)h除關(guān)于docker相關(guān)不用的數(shù)據(jù)來釋放磁盤空間,這篇文章主要介紹了docker prune命令 可定時(shí)清理不常用數(shù)據(jù),需要的朋友可以參考下

場景:使用docker引擎服務(wù)時(shí)間久了,會(huì)發(fā)現(xiàn)磁盤空間越來越大,現(xiàn)在要?jiǎng)h除關(guān)于docker相關(guān)不用的數(shù)據(jù)來釋放磁盤空間

先看下docker system命令

docker system 目前擁有四個(gè)子命令,分別是:

docker system df
docker system events
docker system info
docker system prune

docker system 其中最重要的一個(gè)命令就是 docker system prune 命令,清理沒有使用的數(shù)據(jù),包括鏡像數(shù)據(jù),已經(jīng)停止的容器

查看 docker system 幫助

[root@localhost ~]# docker system --help

Usage:  docker system COMMAND

Manage Docker

Options:
      --help   Print usage

Commands:
  df          Show docker disk usage
  events      Get real time events from the server
  info        Display system-wide information
  prune       Remove unused data

Run 'docker system COMMAND --help' for more information on a command.

docker system df提供Docker整體磁盤使用率的概況,包括鏡像、容器和(本地)volume。所以我們現(xiàn)在隨時(shí)都可以查看Docker使用了多少資源。

[root@localhost ~]# docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              10                  6                   2.652GB             1.953GB (73%)
Containers          6                   6                   6.922MB             0B (0%)
Local Volumes       0                   0                   0B                  0B

docker system prune如果之前的命令展示出 docker 已經(jīng)占用了太多空間,我們會(huì)開始清理。有一個(gè)包辦一切的命令:

[root@localhost ~]# docker system prune
WARNING! This will remove:
        - all stopped containers # 清理停止的容器
        - all networks not used by at least one container #清理沒有使用的網(wǎng)絡(luò)
        - all dangling images #清理廢棄的鏡像
        - all build cache #清理構(gòu)建緩存
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

根據(jù)警告信息可知,這個(gè)命令會(huì)刪除所有關(guān)閉的容器以及dangling鏡像。示例中,含有3個(gè)1GB隨機(jī)文件的鏡像的名稱被占用了,名稱為:,為dangling鏡像,因此會(huì)被刪除。同時(shí),所有的中間鏡像也會(huì)被刪除。

更進(jìn)一步,使用-a選項(xiàng)可以做深度清理。這時(shí)我們會(huì)看到更加嚴(yán)重的WARNING信息:

$ docker system prune -a
WARNING! This will remove:
        - all stopped containers
        - all volumes not used by at least one container
        - all networks not used by at least one container
        - all images without at least one container associated to them
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: test:latest
deleted: sha256:c515ebfa2...
deleted: sha256:07302c011...
deleted: sha256:37c0c6474...
deleted: sha256:5cc2b6bc4...
deleted: sha256:b283b9c35...
deleted: sha256:8a8b9bd8b...
untagged: alpine:latest
untagged: alpine@sha256:58e1a1bb75db1...
deleted: sha256:4a415e366...
deleted: sha256:23b9c7b43...
Total reclaimed space: 2.151GB

這個(gè)命令將清理整個(gè)系統(tǒng),并且只會(huì)保留真正在使用的鏡像,容器,數(shù)據(jù)卷以及網(wǎng)絡(luò),因此需要格外謹(jǐn)慎。比如,我們不能在生產(chǎn)環(huán)境中運(yùn)行prune -a命令,因?yàn)橐恍﹤溆苗R像(用于備份,回滾等)有時(shí)候需要用到,如果這些鏡像被刪除了,則運(yùn)行容器時(shí)需要重新下載。

此時(shí),所有未綁定容器的鏡像將會(huì)被刪除。由于第一次prune命令刪除了所有容器,因此所有鏡像(它們沒有綁定任何容器)都會(huì)被刪除。

如何清理none對象

Docker 采用保守的方法來清理未使用的對象(通常稱為“垃圾回收”),例如鏡像、容器、卷和網(wǎng)絡(luò):
除非明確要求 Docker 這樣做,否則通常不會(huì)刪除這些對象。這可能會(huì)導(dǎo)致 Docker 使用額外的磁盤空間。
對于每種類型的對象,Docker 都提供了一條 prune 命令。
另外,可以使用 docker system prune一次清理多種類型的對象。本主題講解如何使用這些 prune 修剪命令

修剪鏡像

清理none鏡像(虛懸鏡像)
命令: docker image prune
默認(rèn)情況下,docker image prune 命令只會(huì)清理 虛無鏡像(沒被標(biāo)記且沒被其它任何鏡像引用的鏡像)

root@instance-o70no2nw:~# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

清理無容器使用的鏡像
命令: docker image prune -a

默認(rèn)情況下,系統(tǒng)會(huì)提示是否繼續(xù)。要繞過提示,請使用 -f 或 --force 標(biāo)志。
可以使用 --filter 標(biāo)志使用過濾表達(dá)式來限制修剪哪些鏡像。例如,只考慮 24 小時(shí)前創(chuàng)建的鏡像:

$ docker image prune -a --filter "until=24h"

修剪容器

停止容器后不會(huì)自動(dòng)刪除這個(gè)容器,除非在啟動(dòng)容器的時(shí)候指定了 –rm 標(biāo)志。使用 docker ps -a 命令查看 Docker 主機(jī)上包含停止的容器在內(nèi)的所有容器。你可能會(huì)對存在這么多容器感到驚訝,尤其是在開發(fā)環(huán)境。停止?fàn)顟B(tài)的容器的可寫層仍然占用磁盤空間。要清理掉這些,可以使用 docker container prune 命令:

$ docker container prune

WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y

默認(rèn)情況下,系統(tǒng)會(huì)提示是否繼續(xù)。要繞過提示,請使用 -f 或 --force 標(biāo)志。

默認(rèn)情況下,所有停止?fàn)顟B(tài)的容器會(huì)被刪除。可以使用 --filter 標(biāo)志來限制范圍。例如,下面的命令只會(huì)刪除 24 小時(shí)之前創(chuàng)建的停止?fàn)顟B(tài)的容器:

修剪卷
卷可以被一個(gè)或多個(gè)容器使用,并占用 Docker 主機(jī)上的空間。卷永遠(yuǎn)不會(huì)被自動(dòng)刪除,因?yàn)檫@么做會(huì)破壞數(shù)據(jù)。

$ docker volume prune

WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y

修剪網(wǎng)絡(luò)
Docker 網(wǎng)絡(luò)不會(huì)占用太多磁盤空間,但是它們會(huì)創(chuàng)建 iptables 規(guī)則,橋接網(wǎng)絡(luò)設(shè)備和路由表?xiàng)l目。要清理這些東西,可以使用 docker network prune 來清理沒有被容器未使用的網(wǎng)絡(luò)。

$ docker network prune

修剪一切

docker system prune 命令是修剪鏡像、容器和網(wǎng)絡(luò)的快捷方式。在 Docker 17.06.0 及以前版本中,還好修剪卷。在 Docker 17.06.1 及更高版本中必須為 docker system prune 命令明確指定 --volumes 標(biāo)志才會(huì)修剪卷。

$ docker system prune

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

如果使用 Docker 17.06.1 或更高版本,同時(shí)也想修剪卷,使用 --volumes 標(biāo)志。

$ docker system prune --volumes

WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all volumes not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

通常我們定時(shí)任務(wù)刪除即可
比如我這邊場景是鏡像占用磁盤空間很大,那我定時(shí)個(gè)刪除鏡像的任務(wù)
每天凌晨1點(diǎn),刪除72小時(shí)之外所有沒有被使用的鏡像:

[root@develop-server]# crontab -e
0 1 * * * docker image prune -a --force --filter "until=72h"

docker system info (docker info)

這個(gè)命令的縮寫docker info相信大家都很熟悉

[root@localhost ~]# docker system info
Containers: 6
 Running: 6
 Paused: 0
 Stopped: 0
Images: 49
Server Version: 17.06.2-ce
Storage Driver: overlay
 Backing Filesystem: xfs
 Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 3.10.0-514.26.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 24
Total Memory: 31.21GiB
Name: localhost.localdomain
ID: YTL2:6RWX:IZK6:X4XC:XKMO:WVXD:LXPR:E5GN:GEJB:WIUX:L5YH:PDFB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Registry Mirrors:
 http://9zkjjecg.mirror.aliyuncs.com/
 https://docker.mirrors.ustc.edu.cn/
Live Restore Enabled: false

詳細(xì)的解釋

到此這篇關(guān)于docker prune命令 可定時(shí)清理不常用數(shù)據(jù)的文章就介紹到這了,更多相關(guān)docker prune命令 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Docker移除鏡像幾種不同的方法實(shí)戰(zhàn)記錄

    Docker移除鏡像幾種不同的方法實(shí)戰(zhàn)記錄

    在Docker實(shí)戰(zhàn)中,合理刪除不再需要的鏡像,有助于釋放寶貴的磁盤空間,刪除Docker鏡像可以通過多種方式,包括刪除單個(gè)鏡像、強(qiáng)制刪除正在使用的鏡像、刪除未被任何容器引用的所有鏡像以及刪除所有鏡像等,需要的朋友可以參考下
    2024-11-11
  • Docker容器日志占用空間過大的解決方式

    Docker容器日志占用空間過大的解決方式

    當(dāng)我們嘗試查看特定?Docker?容器的日志時(shí),通常會(huì)使用?docker?logs?<容器名稱>?命令,,然而,有時(shí)候會(huì)發(fā)現(xiàn)控制臺持續(xù)輸出日志信息,持續(xù)時(shí)間可能相當(dāng)長,直到最終打印完成,導(dǎo)致日志積累過多,占用了系統(tǒng)磁盤空間,所以本文給大家介紹了解決方法,需要的朋友可以參考下
    2024-03-03
  • CentOS8上用Docker部署開源項(xiàng)目Tcloud的教程

    CentOS8上用Docker部署開源項(xiàng)目Tcloud的教程

    這篇文章主要介紹了CentOS8上用Docker部署開源項(xiàng)目Tcloud,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-01-01
  • docker部署項(xiàng)目/var/lib/docker/overlay2目錄滿了該如何清理

    docker部署項(xiàng)目/var/lib/docker/overlay2目錄滿了該如何清理

    Docker中的/var/lib/docker/overlay2目錄是用于存儲Docker容器的數(shù)據(jù)層和鏡像層的,使用Docker一段時(shí)間后這個(gè)目錄可能會(huì)變得非常大,這篇文章主要給大家介紹了關(guān)于docker部署項(xiàng)目/var/lib/docker/overlay2目錄滿了該如何清理的相關(guān)資料,需要的朋友可以參考下
    2024-04-04
  • 如何通過Dockerfile 創(chuàng)建 kali-novnc

    如何通過Dockerfile 創(chuàng)建 kali-novnc

    這篇文章主要介紹了如何通過Dockerfile 創(chuàng)建 kali-novnc,在Dockerfile所在目錄運(yùn)行相關(guān)命令操作即可完成,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-04-04
  • docker-compose創(chuàng)建網(wǎng)橋,添加子網(wǎng),刪除網(wǎng)卡的實(shí)現(xiàn)

    docker-compose創(chuàng)建網(wǎng)橋,添加子網(wǎng),刪除網(wǎng)卡的實(shí)現(xiàn)

    這篇文章主要介紹了docker-compose創(chuàng)建網(wǎng)橋,添加子網(wǎng),刪除網(wǎng)卡的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • Docker daemon 無法啟動(dòng): does not match with stored UUID錯(cuò)誤解決辦法

    Docker daemon 無法啟動(dòng): does not match with stored UUID錯(cuò)誤解決辦法

    這篇文章主要介紹了Docker daemon 無法啟動(dòng): does not match with stored UUID錯(cuò)誤解決辦法的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • docker部署管理工具portainer-ce的實(shí)現(xiàn)

    docker部署管理工具portainer-ce的實(shí)現(xiàn)

    Portainer是一個(gè)可視化的容器鏡像的圖形管理工具,利用Portainer可以輕松構(gòu)建,管理和維護(hù)Docker環(huán)境,本文主要介紹了docker部署管理工具portainer-ce的實(shí)現(xiàn),感興趣的可以了解一下
    2023-08-08
  • IDEA集成docker實(shí)現(xiàn)遠(yuǎn)程部署的步驟

    IDEA集成docker實(shí)現(xiàn)遠(yuǎn)程部署的步驟

    本文主要介紹了IDEA集成docker實(shí)現(xiàn)遠(yuǎn)程部署的步驟,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Docker部署Django+Mysql+Redis+Gunicorn+Nginx的實(shí)現(xiàn)

    Docker部署Django+Mysql+Redis+Gunicorn+Nginx的實(shí)現(xiàn)

    這篇文章主要介紹了Docker 部署 Django+Mysql+Redis+Gunicorn+Nginx,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評論