在Docker上创建本地Ubuntu存储库

时间:2018-08-24 12:21:32

标签: docker ubuntu ubuntu-16.04 apt

我试图在基于Ubuntu 16.04 xenial的Docker容器上创建本地Ubuntu存储库。我遵循了本教程: https://help.ubuntu.com/community/Repositories/Personal

以下是以root用户身份执行的步骤:

1. mkdir -p /root/repo/amd_64
2. copied all debian packages in /root/repo/amd_64
3. create the script /usr/bin/update-mydebs.sh with the following content:
#! /bin/bash
cd /root/repo/amd_64
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
4. Run the script update-mydebs.sh (I verified the Packages.gz is 
correctly created under /root/repo/amd_64)
5. Added the line in /etc/apt/source.list
deb file:/root/repo amd_64/

当我运行apt-get update时,出现以下问题:

Get:1 file:/root/repo amd_64/ InRelease
Ign:1 file:/root/repo amd_64/ InRelease
Get:2 file:/root/repo amd_64/ Release
Ign:2 file:/root/repo amd_64/ Release
Get:3 file:/root/repo amd_64/ Packages [54.3 kB]
Ign:3 file:/root/repo amd_64/ Packages
Get:3 file:/root/repo amd_64/ Packages
Ign:3 file:/root/repo amd_64/ Packages
Get:3 file:/root/repo amd_64/ Packages
Ign:3 file:/root/repo amd_64/ Packages
Get:3 file:/root/repo amd_64/ Packages
Ign:3 file:/root/repo amd_64/ Packages
Get:3 file:/root/repo amd_64/ Packages
Ign:3 file:/root/repo amd_64/ Packages
Get:3 file:/root/repo amd_64/ Packages
Err:3 file:/root/repo amd_64/ Packages
File not found - /root/repo/amd_64/Packages (2: No such file or 
directory)
Reading package lists... Done
N: Can't drop privileges for downloading as file 
'/root/repo/amd_64/InRelease' couldn't be accessed by user '_apt'. - 
pkgAcquire::Run (13: Permission denied)
W: The repository 'file:/root/repo amd_64/ Release' does not have a 
Release file.
N: Data from such a repository can't be authenticated and is therefore 
potentially dangerous to use. 
N: See apt-secure(8) manpage for repository creation and user 
configuration details.
E: Failed to fetch file:/root/repo/amd_64/Packages  File not found - 
/root/repo/amd_64/Packages (2: No such file or directory)

试图解决该问题,只需将/root/repo/amd_64/Packages.gz解压缩到/ root / repo / amd_64 / Packages中,找不到文件的问题已解决,但又发生了另一个错误:

Get:3 file:/root/repo amd_64/ Packages [169 kB]
Err:3 file:/root/repo amd_64/ Packages
    Could not open file 
    /var/lib/apt/lists/partial/_root_repo_amd%5f64_Packages - open 
    (13: Permission denied)
Reading package lists... Done
N: Can't drop privileges for downloading as file 
'/root/repo/amd_64/InRelease' couldn't be accessed by user '_apt'. - 
pkgAcquire::Run (13: Permission denied)
W: The repository 'file:/root/repo amd_64/ Release' does not have a 
Release file.
N: Data from such a repository can't be authenticated and is therefore 
potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user c 
configuration details.
E: Failed to fetch 
store:/var/lib/apt/lists/partial/_root_repo_amd%5f64_Packages  Could 
not open file /var/lib/apt/lists/partial/_root_repo_amd%5f64_Packages 
- open (13: Permission denied)
E: Some index files failed to download. They have been ignored, or old 
ones used instead.

我注意到网络上与该主题相关的所有教程都与我链接的教程相似,因此我认为它是正确的,但是当我们在Docker容器上应用该过程时,可能需要更改某些内容。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

我也遇到了这个问题。带我进行了大量搜索以查找: https://github.com/radeno/polyfill-service-docker/blob/master/Dockerfile

带有注释:

# work around the following APT issue by using "Acquire::GzipIndexes=false" (overriding "/etc/apt/apt.conf.d/docker-gzip-indexes")
#   Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)
#   ...
#   E: Failed to fetch store:/var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages  Could not open file /var/lib/apt/lists/partial/_tmp_tmp.ODWljpQfkE_._Packages - open (13: Permission denied)

作为更新命令的一部分添加后,此操作对于本地存储库而言按预期工作。