Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

I would use the following approach in the Dockerfile

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...