从 dockerfile 编辑文件 [英] Editing files from dockerfile

查看:37
本文介绍了从 dockerfile 编辑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 docker 映像的/etc/sysctl.conf 中添加几行.有没有一种幂等的方法可以通过 dockerfile 而不是手动编辑并使用 docker commit 方法来做到这一点?

I need to add several lines to /etc/sysctl.conf in a docker image. Is there an idempotent way to do this via a dockerfile rather than editing manually and using the docker commit approach?

推荐答案

我会在 Dockerfile

RUN   echo "Some line to add to a file" >> /etc/sysctl.conf

这应该可以解决问题.如果您希望 替换 一些字符或类似字符,您可以使用 sed 来解决这个问题,例如使用以下:

That should do the trick. If you wish to replace some characters or similar you can work this out with sed by using e.g. the following:

RUN   sed -i "s|some-original-string|the-new-string |g" /etc/sysctl.conf

但是,如果您的问题在于简单地将设置设置为咬"这个问题可能会有所帮助.

However, if your problem lies in simply getting the settings to "bite" this question might be of help.

这篇关于从 dockerfile 编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆