docker镜像大小异常

问题描述 投票:0回答:0

下面是报告的图像 7976d82ebd9f 大小 20GB,你可以看到它下面的层在增长:

<none>                                                                      <none>                      7976d82ebd9f   9 seconds ago   20GB
<none>                                                                      <none>                      69b7404e0fa7   7 minutes ago   14.8GB
<none>                                                                      <none>                      5553abaac35a   7 minutes ago   14.8GB
<none>                                                                      <none>                      c6b650ffd1e9   7 minutes ago   13.2GB
<none>                                                                      <none>                      52c05db14947   9 minutes ago   9.33GB
<none>                                                                      <none>                      6332544fea4b   9 minutes ago   9.33GB
detector-src-2cd5a61.img                                                    latest                      8a48f7c375cd   43 hours ago    9.33GB

但是从里面的图片可以看出应该是<10GB, which corresponds to the expected build+code size:

root@f7b6e187e357:/# du -sh ./*
0   ./bin
4.0K    ./boot
0   ./dev
1.8M    ./etc
4.0K    ./home
0   ./lib
0   ./lib32
0   ./lib64
0   ./libx32
4.0K    ./media
4.0K    ./mnt
698M    ./opt
du: cannot access './proc/11/task/11/fd/4': No such file or directory
du: cannot access './proc/11/task/11/fdinfo/4': No such file or directory
du: cannot access './proc/11/fd/3': No such file or directory
du: cannot access './proc/11/fdinfo/3': No such file or directory
0   ./proc
16K ./root
84K ./run
0   ./sbin
6.3G    ./source
4.0K    ./srv
0   ./sys
4.0K    ./tmp
1.9G    ./usr
34M ./var

想法是在容器内部执行重建,更新源代码但保留

build
目录。 代码被复制到
detector-src-2cd5a61.img
图像中。旧的源目录被删除。构建目录保留,但被新构建覆盖,不会根据
du
输出增长。

  1 FROM detector-src-2cd5a61.img as builder
  2 MAINTAINER MPK Software <[email protected]>
  3 ENV DEBIAN_FRONTEND=noninteractive
  4 
  5 RUN mv /source/build /build \
  6     && rm -rf /build/ubuntu \
  7     && rm -rf /source
  8 COPY . /source/
  9 WORKDIR /source
 10 
 11 RUN mv /build /source/build \
 12     && cd build \
 13     &&  cmake -DCMAKE_BUILD_TYPE=Release \
 14             -DINSTALL_PREFIX=/usr \
 15             -DBUILD_TESTS=OFF ../ \
 16         && make -j $(nproc) \
 17         && make pack

docker image cmake makefile containers
© www.soinside.com 2019 - 2024. All rights reserved.