Fix permission denied issue of ghost blog
I moved the ghost blog to new VM where I hosted the blog within docker.
But when I tried to update the profile image, it reported errors.
Checking the ghost container log, it shows “permission denied error” as below.
2022-04-25 06:12:40 ERROR "POST /ghost/api/admin/images/upload/" 500 67ms
EACCES: permission denied, copyfile '/tmp/4bb7010b22bc5946405418e9711b35f9_processed' -> '/var/lib/ghost/content/images/2022/04/notion-avatar-1647250396306.png'
Looks like it’s a file permission issue.
So I checked the image folder permission in docker container and the ghostdata volume in host machine. It shows that the images under ghostdata volume is owned by root:root but the internal images folder is owned by node. That’s reasonable coz I started docker under root user. And I didn’t create node user, so the internal node user has no right to write to the mounted ghostdata volume.
How to resolve?
Create the node user and restart docker compose services.
useradd node # create node user
sudo usermod -aG docker node # add node to docker group
docker-compose down # stop docker-compose services
docker-compose up -d # start docker-compose services