sed - docker run sed 不起作用

标签 sed docker

我正在接近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 命令正常)。

您还可以创建一个 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 run some/new-image以获得预期的输出。

结论 - 您可能希望在原始镜像 Dockerfile 中运行 sed 命令。

关于sed - docker run sed 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22375300/

相关文章:

Python就地配置值更新

Bash 将分隔文件中的所有整数减一

maven - jib-maven spring boot 配置文件

networking - 卡在从 vagrant 内的 docker 容器转发的端口上的请求

linux - 使用 Sed 多重搜索模式打印特定行

linux - grep 第 n 行 linux 的一部分

bash - Shell 脚本 - 运行正则表达式来修改文件,其中包括文件名

docker - Docker,Kafka-复制在远程代理之间不起作用

amazon-ec2 - AWS BeansTalk 公开 docker 端口

azure - 从 azure 容器注册表中提取镜像时的 imagepullbackoff