You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab流水线报错:/var/lib/apt/lists/partial缺失(权限拒绝)

解决GitLab Runner作业中apt-get权限报错问题

错误原因

Docker类型的GitLab Runner默认以非root用户执行作业,而apt-get update需要写入/var/lib/apt/lists目录,非root用户没有该目录的写入权限,因此抛出"Permission denied"错误。

解决方案

方案1:在作业中以root用户执行

修改流水线配置,添加user: root指定用root用户运行作业,同时明确指定基础镜像:

stages:
  - test_ftp_connection

test_ftp_connection:
  stage: test_ftp_connection
  image: ubuntu:latest
  user: root
  script:
    - apt-get update -qy
    - apt-get install -y ftp
    - ftp -d -n -v 157.96.582.42 <<EOF
      user username password
      passive
      ls
      bye
      EOF
  only:
    - main

方案2:使用预装FTP工具的轻量镜像

换用Alpine镜像,通过apk包管理安装ftp(Alpine默认以root用户运行,且apk不需要额外权限),镜像体积更小、执行更快:

stages:
  - test_ftp_connection

test_ftp_connection:
  stage: test_ftp_connection
  image: alpine:latest
  script:
    - apk add --no-cache ftp
    - ftp -d -n -v 157.96.582.42 <<EOF
      user username password
      passive
      ls
      bye
      EOF
  only:
    - main

方案3:全局配置Runner默认以root运行

如果需要所有作业都用root用户执行,可修改GitLab Runner的config.toml配置文件(通常位于/etc/gitlab-runner/config.toml),在对应runner的[[runners]]块中添加:

user = "root"

修改后重启GitLab Runner服务生效:

sudo gitlab-runner restart

内容的提问来源于stack exchange,提问作者Ahmad Badpey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 23:47:04