docker-compose-viz icon indicating copy to clipboard operation
docker-compose-viz copied to clipboard

Docker - failed to open stream permission denied

Open dschmag opened this issue 3 years ago • 8 comments

I tried docker-compose-viz

$ docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz render -m image docker-compose.yml
Warning: file_put_contents(/input/docker-compose.png): failed to open stream: Permission denied in /dcv/src/application.php on line 138
Linux myserver 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.1

dschmag avatar Aug 26 '21 06:08 dschmag

I am having this issue too. Any ideas on how to fix this?

rahedges avatar Dec 05 '22 16:12 rahedges

This issue is caused by different user ids on the host and in the container. Some user manipulation at the command line might work.

A quick work around is to create an empty output file, set the permissions to match the user in the container and then force-write the generated image over the dummy image.

  1. Run the container and list the id of the user in the container:
docker run --rm -it --name dcv pmsipilot/docker-compose-viz id
uid=1000(dcv) gid=1000(dcv) groups=1000(dcv)
  1. On the host, create an empty file with the name of the output
touch docker-compose.png
  1. Change the owner of the empty output file to match the docker uid and gid found above (1000:1000)
sudo chown 1000:1000 docker-compose.png
  1. Run the container and generate the image as in the original post, but add the --force option to allow the container to overwrite the empty file.
 docker run --rm -it --name dcv -v $(pwd):/input pmsipilot/docker-compose-viz  render -m image --force  docker-compose.yml

rahedges avatar Dec 05 '22 16:12 rahedges

I fixed this by just giving write permissions to the entire project folder

umer936 avatar Mar 14 '23 14:03 umer936

another workaround that is a bit cleaner IMHO: run the container with the --user option

docker run --rm -it --user $UID:$GID --name dcv -v "$(pwd):/input" pmsipilot/docker-compose-viz render -m image docker-compose.yml 

Tazoeur avatar Apr 24 '24 10:04 Tazoeur