I'm encountering a permission issue while trying to execute a script within a Docker container that modifies the host operating system's file system. Specifically, I'm getting a "sed: couldn't open a temporary file" error, as shown below:
sed -i 's[ ]root=[^ ]*/ root=${mender_kernel_root}/' work/rpi/cmdline.txt
sed: couldn't open temporary file work/rpi/sedqWUbSX: Permission denied
The problem exists only with sed command and its temporary files; other commands create/read/write/delete files in the work directory with no errors.
I suspect it's related to permissions, but I'm not sure how to resolve this issue. Can anyone provide guidance on how to troubleshoot and fix this "sed" command permission denied error when running the script in Docker? Any insights or solutions would be greatly appreciated.
Environment: Mac OS Sonoma as host OS, Docker Desktop 4.24.0, Docker Engine 24.0.6, container uses Ubuntu 20.04
P.S. Unfortunately, replacement of sed with other approaches is not an option for me. Switching to a different host OS would also be desirable to avoid.
The problem was caused by VirtioFS, which is now enabled by default in Docker Desktop on Mac OS. Other options (gRPC FUSE and osxfs) work fine with sid
I believe its permission problem since sed creates a temporary file. What You might like to try and check if it works or not:
instead of inplace editing with sed (-i), use sed and redirect it output to a temporary file, then cat temporary file into work/rpi/cmdline.txt
something like this:
sed 's[ ]root=[^ ]*/ root=${mender_kernel_root}/' work/rpi/cmdline.txt > /tmp/this
cat /tmp/this > work/rpi/cmdline.txt
do not redirect sed directly to work/rpi/cmdline.txt since redirects starts before executing the command and it will remove content in work/rpi/cmdline.txt before executing sed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With