Docker容器日志撑爆磁盘排查记录

问题背景 生产环境虚拟机磁盘告警,使用率达到 94%,需要排查占用空间的文件并进行清理。 环境信息 操作系统:Ubuntu(虚拟机) 磁盘容量:1.8T,已使用 1.6T 主要服务:GitLab、MySQL、Redis、Nexus3、SkyWalking 等(均运行在 Docker 中) 排查过程 第一步:定位大文件目录 首先使用 docker system df -v 查看 Docker 各组件的磁盘占用: docker system df -v 发现 Images 和 Volumes 占用正常,但 Containers 数据异常。 进一步检查 Docker 数据目录: du -sh /var/lib/docker/* 输出结果: 88K /var/lib/docker/buildkit 556G /var/lib/docker/containers 37M /var/lib/docker/image 188K /var/lib/docker/network 🔴 发现问题:/var/lib/docker/containers 目录占用了 556GB! 第二步:定位具体容器 查看每个容器的日志文件大小: for id in $(ls /var/lib/docker/containers/); do name=$(docker inspect --format '{{.Name}}' $id 2>/dev/null | tr -d '/') log_file="/var/lib/docker/containers/$id/$id-json.log" if [ -f "$log_file" ]; then size=$(ls -lh "$log_file" | awk '{print $5}') echo "$size - $name ($id)" fi done | sort -rh 输出结果: ...

January 9, 2026 · 2 min

使用GitHub Actions自动构建docker镜像并发布到DockerHub

前言 之前写了一个开源项目,每次打tag的时候都要手动构建docker image然后上传实在是太麻烦了。于是研究了下GitHub Actions,发现非常好用。 本文就来讲一下,如何借助 Github Actions 自动构建兼容多 CPU 架构的 docker 镜像并发布到 DockerHub。 配置 使用build-push-action进行实现多CPU架构镜像构建。按照官方文档可以快速使用起来,但是有几个比较容易出错的地方需要注意。 配置案例 创建配置文件.github/workflows/docker-publish.yml name: Docker # This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. on: push: # Publish semver tags as releases. tags: [ '**' ] env: # Use docker.io for Docker Hub if empty REGISTRY: 'docker.io' # github.repository as <account>/<repo> IMAGE_NAME: ${{ github.repository }} jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write # This is used to complete the identity challenge # with sigstore/fulcio when running outside of PRs. id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer - name: Install cosign uses: sigstore/[email protected] with: cosign-release: 'v2.4.0' # Set up BuildKit Docker container builder to be able to build # multi-platform images and export cache # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 # Login against a Docker registry except on PR # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} # Extract metadata (tags, labels) for Docker # https://github.com/docker/metadata-action - name: Extract Docker metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} 很多配置见名知意,对照官方文档也都能找到答案。有的版本官方案例中使用很长一串具体版本,为了方便使用,我改为了数字版本。 ...

December 9, 2025 · 2 min