在 Docker 中使用 apt-cacher-ng 时,可能会出现以下错误提示:
W: Failed to fetch http://xxx.xxx.xxx.xxx/debian/dists/jessie/InRelease  Unable to find expected entry 'main/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)
这是因为 apt-cacher-ng 的默认配置并不支持处理 main/binary-amd64/Packages 格式的文件,需要手动更改配置文件才能解决问题。
以下是修改 docker-compose.yml 文件的示例代码(假设 apt-cacher-ng 服务的容器名为 apt-cacher-ng):
version: '3'
services:
  apt-cacher-ng:
    image: sameersbn/apt-cacher-ng:3.1.4
    ports:
      - "3142:3142"
    restart: always
    volumes:
      - /srv/docker/apt-cacher-ng:/var/cache/apt-cacher-ng:z
  some-service:
    build: .
    environment:
      - http_proxy=http://apt-cacher-ng:3142/
      - https_proxy=http://apt-cacher-ng:3142/
在上述代码中,通过在 some-service 服务的环境变量中添加代理,将 apt-cacher-ng 服务代理到了它所提供的缓存服务。
完成以上修改后,重启 Docker 就可以生效了。