LoginSignup
0
0

More than 1 year has passed since last update.

【Docker】sed: couldn't open temporary file ./sedxxx: Permission denied 対処法【VirtioFS】

Last updated at Posted at 2023-03-02

状況

Dockerでファイル共有にVirtioFSを使用してコンテナ内でsed -iを実行したところ以下のようなエラーが出ました。

$ sed -i 's/example/EXAMPLE/' sample.txt
sed: couldn't open temporary file ./sedxxx: Permission denied

対処法

次のようにバインドマウントをしていないディレクトリにファイルをコピーします。
その後そのファイルに対してsed -iを実行しオリジナルのファイルにその内容をコピーして戻します。

$ cp ./sample.txt /tmp/sample.txt
$ sed -i 's/example/EXAMPLE/' /tmp/sample.txt
$ cp -f /tmp/sample.txt ./sample.txt

または次のように-iオプションを使用しないようにします。

$ sed 's/example/EXAMPLE/' ./sample.txt > ./sample.txt.tmp
$ mv -f ./sample.txt.tmp ./sample.txt

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0