English 中文(简体)
清除cker/超继2/
原标题:Is it safe to clean docker/overlay2/

我用一些 do罐集装箱在AWS EC2上运行,每fold/lib/docker/overlay2的碎箱在磁盘上生长得非常快。

I m wondering if it is safe to delete its content? or if docker has some kind of command to free up some disk usage.


<><>UPDATE:

我实际尝试了docker system prune -a, 目前已重新启用0Kb。

我/多克/超继2 磁盘的大小也大大高于<条码>多克系统<<>条码>的产出。

After reading docker documentation and BMitch s answer, I believe it is a stupid idea to touch this folder and I will try other ways to reclaim my disk space.

最佳回答

多克人利用var/lib/docker储存你的图像、集装箱和当地名称的卷。 删除这可能导致数据损失,并可能阻止发动机运行。 The overlay2 subdirectory specified with the various filesystem levelss for pornography and instruments.

清理未使用的集装箱和图像,见docker system prune。 还有一些办法可以去除数量和甚至有色图像,但是由于数据损失的可能性,这些图像因缺省而无法使用:

$ docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all             Remove all unused images not just dangling ones
      --filter filter   Provide filter values (e.g.  label=<key>=<value> )
  -f, --force           Do not prompt for confirmation
      --volumes         Prune volumes

悬 a永远不会删除:

  • running containers (list them with docker ps)
  • logs on those containers (see this post for details on limiting the size of logs)
  • filesystem changes made by those containers (visible with docker diff)

此外,在收集垃圾期间,从通常的制片人之外制造的任何东西都不会被cker弄。 这可以从一些其他文字到这一目录,或者从以前的cker车发动机组合(例如,从非盟后勤系统转至超支2,或者可能是在使用户名称空间成为可能之后)。

如果忽视这一建议,你就会从这个档案系统中删除一个如超支的单倍数? 集装箱档案系统是从一个档案系统层收集的,而超中继器是有些码头的 do子(当集装箱运行时,在<代码>mount/code>的输出中见到)。 删除其中一部分在使用时,将从一个运行的集装箱中删除档案系统的空白,并可能打破从撞击图像中开启新集装箱的能力。 见,关于许多可能的结果之一,见


为了完全把 do锁重新引入清洁状态,你可以删除整个目录, 而不仅仅是超莱2等次级标题:

# danger, read the entire text around this code before running
# you will lose data
sudo -s
systemctl stop docker
rm -rf /var/lib/docker
systemctl start docker
exit

发动机将在一个完全空洞的国家重新启用,这意味着你将失去一切:

  • images
  • containers
  • named volumes
  • user created networks
  • swarm state
问题回答

我认为,这对我来说是最好的:

docker image prune --all

否则,Docker将不会去除被点名的图像,即使这些图像没有使用。 这一指挥将消除未使用的图像。

图像中的每个层层是<代码>/usr/lib/docker/overlay2/的夹。

我有这个问题。 这是巨大的标志。 记录如下:

/var/lib/docker/containers/<container id>/<container id>-json.log

你们可以在指挥线或堆积档案中加以管理。 见。 伐木司机

我个人将这三条线添加到我的cker手。 yml file:

my_container:
  logging:
    options:
      max-size: 10m

如果您的系统也被用于制作图像,那么你可能会对建筑商制造的垃圾进行清扫,使用:

docker buildx prune --all

以及

docker builder prune --all

快速增长的<代码>overlay2也有问题。

/var/lib/docker/overlay2 - is a folder where docker store writable layers for your container. docker system prune -a - may work only if container is stopped and removed.

我能把空间消耗量输入<代码>overlay2并进行调查。

该双管装有其他散射器。 每一组都有多个文件,包括<代码>diff。

<编码>diff 倍数——包含由集装箱书写的实际差异,其集装箱结构精确为您的集装箱(至少是我的情况――ubuntu 18)。

<>0> i ve used du -hsc /var/lib/docker/overlay2/LONGHASHHHHHHHH/diff/tmp to figures out that /tmp 我的集装箱内是经过污染的“

a. 工作周期 <代码>docker 运行 指令,绘制内幕图<代码>/tmp, 并贴上背书和打上掩饰该夹的座标。

艰巨的任务很简单:

  • sudo nano /etc/crontab
  • */30 * * * * root rm -rf /tmp/container-data/tmp/*
  • save and exit

NOTE:overlay2 is system docker rafter, and they may change it structure anytime. 以上一切都基于我在那里看到的情况。 只因为系统完全没有空间,甚至会 would让我冲入 do集装箱,才有可能进入cker锁的玻璃结构。

落后农业

这个问题的责任可以分为我们对集装箱量进行不当配置和向这些量书写的码头泄漏(未能释放)临时数据的问题。 我们应当绘制所有集装箱外临时/标识/高档夹的地图(或者接收文件夹或其他持久性储存要求),这些箱子经常和(或)大量书写。 多克公司不负责清理所有自动创建的所谓“企业经营人”,其地址是:/var/lib/docker/overlay2/*/diff/*。 这些“非永久性”夹的部件应在集装箱停泊后自动由 do子提纯,但显然不是(如果集装箱仍在运行,甚至不可能从东道方提纯,并且可以持续几个月)。

工作情况

一项工作需要仔细的人工清理,虽然在其他地方已经描述过,但你仍可能从我的案例研究中找到一些内容,我试图尽量使案例研究具有启发性和普遍性。

因此,实际发生的是(在我的案件中,clair-scanner)在几个月内将数以百计的数据输入/diff/tmp。 <代码>overlay2

du -sch /var/lib/docker/overlay2/<long random folder name seen as bloated in df -haT>/diff/tmp

271G total

因此,由于在<代码>/diff/tmp上的所有这些子夹都是初步的自我解释(所有形式为clair-scanner-*,并且已经过时了设定日期),我停止了相关的集装箱(docker end clair,并从diff/tmp中仔细删除这些过时的子夹,先是谨慎地从单一(最老的)一开始,并测试对码头发动机的影响(这确实要求重新启动[<编码系统>sctl dockercode/code],以重新启用:

rm -rf $(ls -at /var/lib/docker/overlay2/<long random folder name seen as bloated in df -haT>/diff/tmp | grep clair-scanner | tail -1)

我收回了数以百计的软磁场,而无需重新安装 do器或整整整整套。 所有运行的集装箱都不得不在某个时候被拦截,因为要重新启用磁盘空间,就必须让 do人重新启用磁盘空间,从而确保首先,你的破碎集装箱在另一个天线上运行正确。 但我希望<代码>docker prune的指挥可涵盖过时的<代码>/diff/tmp。 (或甚至<代码>/diff/*)数据(通过另一条交换)。

这个问题现在是一个3年历史的问题,你可以读到多克论坛的丰富和有色的历史,1920年提出了旨在应用上述解决办法的<<0>标志的变量,似乎已经在几个层次上开展工作:

朋友,为了保持你能够使用指挥力的一切清洁:

docker system prune -a && docker volume prune

www.un.org/spanish/ecosoc WARNING:DO NOT USE IN A PRODUCTION SYSTEM

/# df
...
/dev/xvda1      51467016 39384516   9886300  80% /
...

Ok,请先尝试制

#/ docker system prune --volumes
...
/# df
...
/dev/xvda1      51467016 38613596  10657220  79% /
...

似乎没有那么大,好像它清理了少数兆字节。 让现在cra:

/# sudo su
/# service docker stop
/# cd /var/lib/docker
/var/lib/docker# rm -rf *
/# service docker start
/var/lib/docker# df
...
/dev/xvda1      51467016 8086924  41183892  17% /
...

Nice! Just remember that this is NOT recommended in anything but a throw-away server. At this point Docker s internal database won t be able to find any of these overlays and it may cause unintended consequences.

“官方”答案是用“prune”的指令进行清洗,但在<代码>overlay2上没有实际清理垃圾。

因此,为了回答原始问题,可以做的是:

Disclaimer: Be careful when applying this. This may result broking your Docker object!

  • List folder names (hashes) in overlay2
  • Inspect your Docker objects (images, containers, ...) that you need (A stopped container or an image currently not inside any container do not mean that you do not need them).
  • When you inspect, you will see that it gives you the hashes that are related with your object, including overlay2 s folders.
  • Do grep against overlay2 s folders
  • Note all folders that are found with grep
  • Now you can delete folders of overlay2 that are not referred by any Docker object that you need.

例:

请允许我在您的<代码>overlay2目录内注明这些夹,

a1b28095041cc0a5ded909a20fed6dbfbcc08e1968fa265bc6f3abcc835378b5
021500fad32558a613122070616963c6644c6a57b2e1ed61cb6c32787a86f048

仅凭IDc777cf06a6e的图像。

然后:

docker inspect c777cf06a6e3 | grep a1b2809
docker inspect c777cf06a6e3 | grep 021500

Imagine that first command found something whereas the second nothing.

然后,您可删除<代码>overlay2的复印件:

rm -r 021500fad32558a613122070616963c6644c6a57b2e1ed61cb6c32787a86f048

回答问题标题:

  • Yes, it is safe deleting dxirectly overlay2 folder if you find out that it is not in use.
  • No, it is not safe deleting it directly if you find out that it is in use or you are not sure.

在以上评论中,人们建议采用像清晰的干燥量、图像、卸载集装箱等系统, 有时,如果你用空出的目录(当地卷)填充分数,那就会产生太多的标志。 在该案中,我发现以下一点非常令人感兴趣,即我/瓦尔部分磁盘上的消耗空间。

du -ahx /var/lib | sort -rh | head -n 30

This command will list top 30, which is consuming most space on a single disk. Means if you are using external storage with your containers, it consumes a lot of time to run du command. This command will not count mount volumes. And is much faster. You will get the exact directories/files which are consuming space. Then you can go to those directories and check which files are useful or not. if these files are required then you can move them to some persistent storage by making change in app to use persistent storage for that location or change location of that files. And for rest you can clear them.

I navigated to the rafter including overlay2. 采用<代码>du-shc overlay2/*,我发现有25 G of junk in overlay2。 运行docker system prune -af. Total Reaïed Space: 1.687/code>,因此,我认为该系统没有清理。 然而,我接着跑了<代码>du -shc overlay2/*。 仅仅看到超支2 只剩下80克朗,这样它就能够工作。

仔细看,cker弄:

http://stackoverflow.com/users/2536614/mert-mertce。 Mert Mertce s

然而,自撰写文字以来,我注意到,我们的建筑服务器上的额外目录是瞬时的,即Docker似乎正在清理,尽管进展缓慢。 我不知道,如果有人争论要取消董事,多克人是否会 up。 我们目前的解决办法是使用docuum ,加上>>>>额外间接费用(150+GB)。

#!/bin/bash
[[ $(id -u) -eq 0 ]] || exec sudo /bin/bash -c "$(printf  %q   "$BASH_SOURCE" "$@")"
progname=$(basename $0)
quiet=false
no_dry_run=false
while getopts ":qn" opt
do
    case "$opt" in
      q)
          quiet=true
          ;;
      n)
          no_dry_run=true
          ;;
      ?)
          echo "unexpected option ${opt}"
          echo "usage: ${progname} [-q|--quiet]"
          echo "    -q: no output"
          echo "    -n: no dry run (will remove unused directories)"
          exit 1
          ;;
    esac
done
shift "$(($OPTIND -1))"

[[ ${quiet} = false ]] || exec /bin/bash -c "$(printf  %q   "$BASH_SOURCE" "$@")" > /dev/null

echo "Running as: $(id -un)"

progress_bar() {
    local w=80 p=$1;  shift
    # create a string of spaces, then change them to dots
    printf -v dots "%*s" "$(( $p*$w/100 ))" ""; dots=${dots// /.};
    # print those dots on a fixed-width space plus the percentage etc.
    printf "
e[K|%-*s| %3d %% %s" "$w" "$dots" "$p" "$*";
}

cd /var/lib/docker/overlay2
echo cleaning in ${PWD}
i=1
spi=1
sp="/-|"
directories=( $(find . -mindepth 1 -maxdepth 1 -type d | cut -d/ -f2) )
images=( $(docker image ls --all --format "{{.ID}}") )
total=$((${#directories[@]} * ${#images[@]}))
used=()
for d in "${directories[@]}"
do
    for id in ${images[@]}
    do
        ((++i))
        progress_bar "$(( ${i} * 100 / ${total}))" "scanning for used directories ${sp:spi++%${#sp}:1} "
        docker inspect $id | grep -q $d
        if [ $? ]
        then
            used+=("$d")
            i=$(( $i + $(( ${#images[@]} - $(( $i % ${#images[@]} )) )) ))
            break
        fi
    done
done
echo -e " " # get rid of spinner
i=1
used=($(printf  %s
  "${used[@]}" | sort -u))
unused=( $(find . -mindepth 1 -maxdepth 1 -type d | cut -d/ -f2) )
for d in "${used[@]}"
do
    ((++i))
    progress_bar "$(( ${i} * 100 / ${#used[@]}))" "scanning for unused directories ${sp:spi++%${#sp}:1} "
    for uni in "${!unused[@]}"
    do
        if [[ ${unused[uni]} = $d ]]
        then
            unset  unused[uni] 
            break;
        fi
    done
done
echo -e " " # get rid of spinner
if [ ${#unused[@]} -gt 0 ]
then
    [[ ${no_dry_run} = true ]] || echo "Could remove:  (to automatically remove, use the -n, " " "no-dry-run" " " flag)"
    for d in "${unused[@]}"
    do
        if [[ ${no_dry_run} = true ]]
        then
            echo "Removing $(realpath ${d})"
            rm -rf ${d}
        else
            echo " $(realpath ${d})"
        fi
    done
    echo Done
else
    echo "All directories are used, nothing to clean up."
fi

For me prune with image and volume didn t work.

首先检查磁盘空间的使用。 您可在ncdu上接下;最佳磁盘空间通用芯I能够穿过。 它将展示所占用的名录英明空间,管理档案系统有许多有益的建筑控制。 这将给你一个公平的想法,即特定进程和名录占用更多的记忆。

sudo ncdu -x /var 

回到cker,一旦你确信 do是带更多磁盘的空间。 你们可以尝试放开,如果皮条不清洗,则试图用以下指挥清除 d积。 这不会删除任何集装箱或任何使用量。

docker volume rm $(docker volume ls -qf dangling=true)

标准做法还限制集装箱记录。 多克公司违约后将无限期地储存集装箱记录。 您可以通过在Docker daemon配置文档中设定一个限值来限制集装箱记录使用的软磁空间(/etc/docker/daemon.json)。 例如,你可以增加以下线,将集装箱记录限制在50MB。 如果没有 file。 json 你可以补充一点。

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "50m"
  }
}

在对达尼蒙组合档案进行改动后,你不得不重新开始Docker daemon与 su公司重新开始指挥。

DON TDOTHIS IN PRODUC

@ravi-luthra在技术上做了工作,但有一些问题!

就我而言,我只是试图收回磁盘空间。 <代码>lib/docker/overlay<>/code> , 夹时有30英镑的空间,我只定期操作几个集装箱。 浏览像码头一样,对数据泄漏有一些问题,一些临时数据在集装箱停泊时没有清除。

因此,我接着删除了<代码>lib/docker/overlay的所有内容。 之后,我的 do笑会变得不可使用。 当我试图操作或建造任何集装箱时,我给我这个错误:

failed to create rwlayer: symlink ../04578d9f8e428b693174c6eb9a80111c907724cc22129761ce14a4c8cb4f1d7c/diff /var/lib/docker/overlay2/l/C3F33OLORAASNIYB3ZDATH2HJ7: no such file or directory

Then with some trial and error, I solved this issue by running

(待定) 这将删除 do中的所有数据。

docker system prune --volumes -a

So It is not recommended to do such dirty clean ups unless you completely understand how the system works.

就我而言,systemctl end docker 然后,systemctlstart docker/code> somehow auto freespace /var/lib/docker/*

I had the same problem, in my instance it was because ´var/lib/docker´ directory was mounted to a running container (in my case google/cadvisor) therefore it blocked docker prune from cleaning the folder. Stopping the container, running docker prune -and then rerunning the container solved the problem.

集装箱的档案系统是/变压/变压器中的所有物品。 如果你停止所有集装箱,并放开这些集装箱,那么你最后就应该把双手 empty空起来。 你可能真的不希望,那么,不要随意地去掉在那里的 st。 <>没有直接删除中的东西。 有时,你会放弃,但出于如此众多的原因,这是不可思议的。

Do this instead:

sudo bash
cd /var/lib/docker
find . -type f | xargs du -b  | sort -n

你们看到的是底线上最大的档案。 如果你想要,就这些集装箱中的哪些箱子而言,用<条码>do车外ec-集装箱名称---/bin/sh

You can also put docker system prune -a -f on a daily/weekly cron job as long as you aren t leaving stopped containers and volumes around that you care about. It s better to figure out the reasons why it s growing, and correct them at the container level.

多克人显然保留了旧式集装箱图像的图像层。 如果你在不停的情况下更新其运行的集装箱图像(ame子),可能发生这种情况:

docker-compose pull
docker-compose up -d

在更新《<<条码>条码>条码>之前,在我的案件中,时间缩短不是问题。

我最近也有一个类似的问题,即超支2越大越大,越大,但我无法说明大部分空间的消耗量。

<代码>df显示,超额2在规模上约为24GB。

缩略语 我试图对所占领的场地进行清点。 并且失败。

The difference came from the fact that deleted files (mostly log files in my case) where still being used by a process (Docker). Thus the file doesn’t show up with du but the space it occupies will show with df.

A reboot of the host machine helped. Restarting the docker container would probably have helped already… This article on linuxquestions.org helped me to figure that out.

Maybe this folder is not your problem, don t use the result of df -h with docker. Use the command below to see the size of each of your folders:

echo; pwd; echo; ls -AlhF; echo; du -h --max-depth=1; echo; du-sh

之所以出现超支,是因为其中一个集装箱有记录。 至少是我的cker。 多克停止并开始解决这一问题,但只是暂时的解决办法。 您要么将关闭标识,要么每天重新启用集装箱。

你可以发现集装箱所覆盖的地区,指挥线如下。

du -sh /var/lib/docker/containers/*

在我的案件中,我的磁盘正在填充,我发现,我的网络服务器集装箱中的波纹/波长完全是老的巴布亚新几内亚档案。 显然,一旦上载,这些申请就没有连接起来。

My solution was far simpler than everything here. I just went into the container:

docker exec -it{container_name} bash

and deleted /tmp/*.png and I released a ton of disk space. Sometimes the solution is simple and it s almost always a tmp directory filling up.

i did cleaned the /overlay2 folder. it messed up my system in start. but doing a simple sudo systemctl restart docker, solved the issue

我阅读了其他评论,并测试了自己,因此,我找到了一些解决办法,清理了超支2 倍数,但并没有删除你的数据。 然而,ALWAYS BACKUP FOR FAETY。

1, Solution 1: just use basic docker prune command. Make sure your docker containers are running, then run this command to clean all unused containers, images ...

docker system prune -a

2, 解决方案2:使用“do堆肥”。 我发现,我通常停止由“多克堆肥站”指挥器 app。 然后,我使用下限指挥,许多磁盘空间被放出。

docker compose down
docker compose up

3, 解决方案3: 重开码头服务

sudo systemctl restart docker

4, Solution 4: directly delete contents in folder overlay2. You ll need to delete your containers and images too, because they re linked to overlay2 folder. But make sure you keep your old volumes so you don t lose your app data and your app can run smoothly after you run docker again. Do all below steps.

# Step 1: down your docker compose to delete your containers and images
docker compose down --rmi

# Step 2: delete other unused containers, images ...
docker system prune -a

# Step 3: delete overlay2 folder in /var/lib/docker/overlay2. 
# Make sure you have permissions to view and delete this folder 
# In my case, I need to switch to root user with "sudo su" command
sudo su
cd /var/lib/docker
rm -rf overlay2
mkdir overlay2

# Step 4: restart your docker service
sudo systemctl restart docker

# Step 5: move to your app folder, up again
docker compose up
docker system prune -af && docker image prune -af




相关问题
Unable to connect to docker container inside windows server

As title. I am developing a system with many docker images with ASP.Net MVC core projects. I am publishing these docker images into a docker engine installed on Windows Server OS, and I found that I ...

Only can see postgreSQL as an admin

After installed Wsl and Docker, can t access PSQL and other things. I was studying Docker, and installed the latest version. So far so good, I received an error about the WSL version, saw some ...

make docker-compose block until healthy without `depends_on`

I am working with a team that uses docker-compose to start a set of helper services, but does not use docker when the code is being developed. Here, docker-compose is just a convenient way to run the ...

change grafana port using docker host network

I am trying to spin up a grafana container in docker, however my setup in docker does not allow ipv4 forwarding and thus I cannot use the default bridge network in docker. All I can use is the host ...

Pip instalation for Python 3.11 in docker

I have Dockerfile to build image for Django project that uses Python 3.11 and runs in poetry environment (see content below). Problem is when I try to donwload get-pip.py file and run it using Python, ...

在 Dockerfile 中运行 composer install

我正在尝试将我的Laravel应用程序进行Docker化。 该应用程序已经构建并在Git中,但我将vendor文件夹添加到了.gitignore中。 我添加了一个Dockerfile,看起来像这样: FROM php:7.1-fpm-alpine RUN apk update ...