我正在接近Docker.我创建了Debootstraping Debian Jessie的映像,我想将contrib部分添加到APT源文件中.
/etc/apt/sources.list的内容是:
$docker run some/image cat /etc/apt/sources.list
deb http://debian.fastweb.it/debian jessie main
deb http://debian.fastweb.it/debian jessie-updates main
deb http://security.debian.org/ jessie/updates main
我希望他们是:
deb http://debian.fastweb.it/debian jessie main contrib
deb http://debian.fastweb.it/debian jessie-updates main contrib
deb http://security.debian.org/ jessie/updates main contrib
所以我运行了这个命令:
docker run some/image sed -i 's/main/main contrib/g' /etc/apt/sources.list
哪个没有错误退出;但它不会更新/etc/apt/sources.list内容:
$docker run some/image cat /etc/apt/sources.list
deb http://debian.fastweb.it/debian jessie main
deb http://debian.fastweb.it/debian jessie-updates main
deb http://security.debian.org/ jessie/updates main
最佳答案
您没有更改图像.您基于图像启动了一个容器.然后,您运行sed命令并更改了文件内容.检查docker ps -a以查看刚刚关闭的容器的ID.如果您使用docker cp提取文件,则应该看到它已按预期更改(假设sed命令正常).
原文链接:/docker/532529.html您还可以创建一个Dockerfile
FROM some/image
RUN sed -i 's/main/main contrib/g' /etc/apt/sources.list
# this command is just temporary,you probably are going to do something else
CMD cat /etc/apt/sources.list
并运行新映像docker运行some / new-image以获得预期的输出.
结论-您可能想在原始映像Dockerfile中运行sed命令.