sed: cannot rename ./sed6x9apB: Operation not permitted using docker-compose with WordPress image
WordPress container fails to start when using docker-compose, where there are existing WordPress files, aborting with the following error:
sed: cannot rename ./sedtpghTB: Operation not permitted
Error only occurs when WordPress files are hosted on a VirtualBox (vboxsf) shared folder. Sharing the folder over SMB/CIFS avoids the error.
Setup:
- Host: Win 10 (64b)
- Guest: 3.16.0-4-amd64 (debian_version 8.6) Guest/Vbox version: 5.1.12 r112440 (Qt5.6.2)
- WordPress files are shared out using a VirtualBox shared folder mounted at
/media/vmhost
Here is the output of docker-compose config:
networks: {}
services:
db:
environment:
MYSQL_DATABASE: my_db_name
MYSQL_PASSWORD: 'MY_ROOT_PASSWORD'
MYSQL_ROOT_PASSWORD: 'MY_ROOT_PASSWORD'
MYSQL_USER: root
image: mysql:5.7
ports:
- 3306:3306
restart: never
volumes:
- db_data:/var/lib/mysql:rw
wordpress:
depends_on:
- db
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: my_db_name
WORDPRESS_DB_PASSWORD: 'MY_PASSWORD'
WORDPRESS_DB_USER: root
image: wordpress:latest
ports:
- 80:80
restart: never
volumes:
- /media/vmhost/www/test:/var/www:rw
- /media/vmhost/www/test/public_html:/var/www/html:rw
version: '2.0'
volumes:
db_data: {}
wp_data: {}
When I attempt a sed on the vboxsf share, I get a similar error, but only when the source file is readonly.
echo 'hello' > hello.txt
chmod a-w hello.txt
sed -i 's/hello/goodbye/' hello.txt
error:
sed: cannot rename ./sed6x9apB: Operation not permitted
output of mount | grep www
www on /media/vmhost/www type vboxsf (rw,nodev,relatime)
When I use a CIFS share , mounted at /media/vmhost/www2 , everything works fine.
//my_laptop/www on /media/vmhost/www2 type cifs (rw,relatime,vers=1.0,sec=ntlm,cache=strict,username=vboxsf,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.5,file_mode=0777,dir_mode=0777,nounix,serverino,noperm,rsize=61440,wsize=65536,actimeo=1)
Solution 1:
This appears to be a bug with VirtualBox, see Ticket #4890 .
Per frank's reply:
fixed for Linux hosts but not for Windows hosts. In contrast to Linux where a file can be removed if the directory is writable but the file itself is read-only, a read-only file cannot be removed on Windows
This impacts sed since sed makes a copy of the source file ( in this case wp-config-sample.php ) to a temporary file, and then attempts to make the replacements which windows won't support since the copy is also readonly.
For some reason, a proper share using CIFs is not impacted.
Workaround 1: Make the source file writeable and restart the container.
chmod a+w wp-config-sample.php
docker-compose up
Workaround 2: Use a CIFS share.
- On your Windows machine, share out the directory containing your WordPress files using the Windows Advanced sharing properties of the directory.
-
On your VirtualBox VM, add the following to /etc/fstab
//my_laptop/www /media/vmhost/www cifs username=WINDOWS_USER,password=WINDOWS_USER_PASSWORD,file_mode=0777,dir_mode=0777,iocharset=utf8,noperm,sec=ntlm 0 0
-
mount
mount -a