Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!
Did you like my answer?
To address the issue of fopen_s() returning error 13 (permission denied) when trying to create a file in a bind-mounted directory inside a Docker container on TorizonCore, you need to ensure that the user inside the container has the appropriate permissions to write to the bind-mounted directory.
Here are a few steps to troubleshoot and resolve this issue:
-
Check Directory Permissions on Host:
Ensure that the./logsdirectory on the host (TorizonCore) has the correct permissions to allow writing by the user inside the container.sudo chmod -R 777 ./logsThis command will give read, write, and execute permissions to all users for the
./logsdirectory. Adjust the permissions as needed for your security requirements. -
Ensure User Permissions Inside Container:
By default, thetorizonuser inside the container should have the necessary permissions. However, if your application is running as a different user, you need to ensure that this user has the appropriate permissions.You can add the
torizonuser to the necessary groups or run the container as thetorizonuser. Here’s how you can modify yourdocker-compose.ymlto run the container as thetorizonuser:version: "3.9" services: servicename-debug: build: context: . dockerfile: Dockerfile.debug volumes: - type: bind source: ./logs target: /tmp/logs image: ${LOCAL_REGISTRY}:5002/servicename-debug:${TAG} user: torizon privileged: true ports: - 6502:6502 -
Verify UID/GID Consistency:
Ensure that the UID and GID of the user inside the container match those on the host. This can help avoid permission issues. You can check the UID and GID of thetorizonuser inside the container and ensure they match the owner of the./logsdirectory on the host.id torizonIf needed, you can change the ownership of the
./logsdirectory on the host to match the UID and GID of thetorizonuser.sudo chown -R <UID>:<GID> ./logs -
Debugging Permissions:
If the above steps do not resolve the issue, you can debug the permissions by running an interactive shell inside the container and checking the permissions directly.docker exec -it <container_id> /bin/bash ls -l /tmp/logs touch /tmp/logs/testfileThis will help you identify if there are any permission issues directly inside the container.
By following these steps, you should be able to resolve the permission denied issue and ensure that your C++ application can log persistently to the bind-mounted directory.
Please, also check if these links can help you solve your problem: