docker-compose-viz
docker-compose-viz copied to clipboard
Docker - failed to open stream permission denied
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
I am having this issue too. Any ideas on how to fix this?
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.
- 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)
- On the host, create an empty file with the name of the output
touch docker-compose.png
- 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
- 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
I fixed this by just giving write permissions to the entire project folder
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