Issue with Mounting Volume in Toradex

The specifications of the board I am using are as follows:

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           6.6.54-7.1.0-devel-g8de35b780872 #1-Torizon SMP PREEMPT Mon Nov 25 16:38:54 UTC 2024
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree =/ostree/boot.1/torizon/6c6d5766f69270798477063a8e27f581de86f6b73b5bfac94c785339d3578ba7/0
Distro name:              NAME="Torizon OS"
Distro version:           VERSION_ID=7.1.0-devel-20241128-build.107
Distro variant:           VARIANT="Docker"
Hostname:                 verdin-imx8mp-15141602
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Verdin iMX8M Plus WB on Verdin Development Boa                                                                                                             rd
Toradex version:          0058 V1.1A
Serial number:            15141602
Processor arch:           aarch64
------------------------------------------------------------

I am working on a C# program in Visual Studio Code that generates a log.txt file within a Docker container. To ensure data persistence, I am attempting to mount a volume to store the log.txt file in the local storage of the Toradex board.

The relevant files are attached to this email:
• Program.cs: Contains the program code.
• docker-compose.yml:

services:
      consoleapp-debug:
        restart: always
        build:
        context: .
      dockerfile: Dockerfile.debug
    image: ${LOCAL_REGISTRY}:5002/consoleapp-debug:${TAG}
    ports:
      - ${DEBUG_SSH_PORT}:${DEBUG_SSH_PORT}
    environment: 
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://+:80
      - DOTNET_RUNNING_IN_CONTAINER=true
      - DOTNET_USE_POLLING_FILE_WATCHER=true
    volumes:
      - logvolume:/home/torizon/app/log
    
  consoleapp:
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
    image: ${DOCKER_LOGIN}/consoleapp:${TAG}
    volumes:
      - logvolume:/home/torizon/app/log
volumes:
  logvolume:

The Issue:
When I run the program without mounting the volume, it works perfectly without any errors. However, when I attempt to mount the volume to make the log.txt file persistent, the program encounters the following permission error:


[+] Running 1/1
✔ Container torizon-consoleapp-debug-1  Started                                                                                                                                                               0.8s 
 *  Terminal will be reused by tasks, press any key to close it. 

*  Executing task: rsync -P -av --no-o --no-g -e ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null /home/torizon/consoleApp/bin/Debug/net8.0/linux-arm64/publish/ torizon@192.168.0.41:/home/torizon/app 

Warning: Permanently added '[192.168.0.41]:2222' (ED25519) to the list of known hosts.
sending incremental file list
rsync: [generator] failed to set times on "/home/torizon/app/.": Operation not permitted (1)
./
BouncyCastle.Cryptography.dll
         32,768   0%    0.00kB/s    0:00:00  rsync: [receiver] mkstemp "/home/torizon/app/.BouncyCastle.Cryptography.dll.5kfSIq" failed: Permission denied (13)
      7,161,624 100%   13.96MB/s    0:00:00 (xfr#1, to-chk=19/21)
Google.Protobuf.dll
        473,376 100%  926.42kB/s    0:00:00 (xfr#2, to-chk=18/21)
K4os.Compression.LZ4.Streams.dll
         84,992 100%  166.00kB/s    0:00:00 (xfr#3, to-chk=17/21)
K4os.Compression.LZ4.dll
         70,656 100%  137.72kB/s    0:00:00 (xfr#4, to-chk=16/21)
K4os.Hash.xxHash.dll
         13,312 100%   25.90kB/s    0:00:00 (xfr#5, to-chk=15/21)
MySql.Data.dll
      1,186,816 100%    2.17MB/s    0:00:00 (xfr#6, to-chk=14/21)
System.Configuration.ConfigurationManager.dll
         32,768   7%   61.19kB/s    0:00:06  rsync: [receiver] mkstemp "/home/torizon/app/.Google.Protobuf.dll.5gFqfW" failed: Permission denied (13)
        442,632 100%  762.36kB/s    0:00:00 (xfr#7, to-chk=13/21)
System.Diagnostics.EventLog.dll
         51,872 100%   89.18kB/s    0:00:00 (xfr#8, to-chk=12/21)
System.IO.Pipelines.dll
         79,512 100%  136.46kB/s    0:00:00 (xfr#9, to-chk=11/21)
System.IO.Ports.dll
         74,536 100%  127.70kB/s    0:00:00 (xfr#10, to-chk=10/21)
System.Security.Cryptography.ProtectedData.dll
         36,616 100%   62.62kB/s    0:00:00 (xfr#11, to-chk=9/21)
System.Security.Permissions.dll
        114,448 100%  195.39kB/s    0:00:00 (xfr#12, to-chk=8/21)
System.Windows.Extensions.dll
         27,424 100%   46.50kB/s    0:00:00 (xfr#13, to-chk=7/21)
ZstdSharp.dll
rsync: [receiver] mkstemp "/home/torizon/app/.K4os.Compression.LZ4.Streams.dll.VBOWDG" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.K4os.Compression.LZ4.dll.f3Zdai" failed: Permission denied (13)
         32,768   7%   55.46kB/s    0:00:06  rsync: [receiver] mkstemp "/home/torizon/app/.K4os.Hash.xxHash.dll.ey1zSP" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.MySql.Data.dll.3fdCA7" failed: Permission denied (13)
        411,136 100%  691.05kB/s    0:00:00 (xfr#14, to-chk=6/21)
consoleApp
         72,568 100%  121.56kB/s    0:00:00 (xfr#15, to-chk=5/21)
consoleApp.deps.json
         30,560 100%   51.19kB/s    0:00:00 (xfr#16, to-chk=4/21)
consoleApp.dll
          5,120 100%    8.58kB/s    0:00:00 (xfr#17, to-chk=3/21)
consoleApp.pdb
         12,344 100%   20.68kB/s    0:00:00 (xfr#18, to-chk=2/21)
consoleApp.runtimeconfig.json
            257 100%    0.43kB/s    0:00:00 (xfr#19, to-chk=1/21)
libSystem.IO.Ports.Native.so
         14,744 100%   24.65kB/s    0:00:00 (xfr#20, to-chk=0/21)
rsync: [receiver] mkstemp "/home/torizon/app/.System.Configuration.ConfigurationManager.dll.CKBC9e" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.System.Diagnostics.EventLog.dll.kzQQZl" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.System.IO.Pipelines.dll.cE7EWt" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.System.IO.Ports.dll.xL2MQD" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.System.Security.Cryptography.ProtectedData.dll.i4nwbF" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.System.Security.Permissions.dll.zP8ALE" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.System.Windows.Extensions.dll.oExhwi" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.ZstdSharp.dll.loLzPW" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.consoleApp.QpxGRV" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.consoleApp.deps.json.xHLEWd" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.consoleApp.dll.MKRUzt" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.consoleApp.pdb.gVZiAb" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.consoleApp.runtimeconfig.json.sgEP5V" failed: Permission denied (13)
rsync: [receiver] mkstemp "/home/torizon/app/.libSystem.IO.Ports.Native.so.Kfo3Ll" failed: Permission denied (13)

sent 10,368,617 bytes  received 399 bytes  6,912,677.33 bytes/sec
total size is 10,364,545  speedup is 1.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1338) [sender=3.2.7]

*  The terminal process "rsync '-P', '-av', '--no-o', '--no-g', '-e', 'ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null', '/home/torizon/consoleApp/bin/Debug/net8.0/linux-arm64/publish/', 'torizon@192.168.0.41:/home/torizon/app'" terminated with exit code: 23. 
 *  Terminal will be reused by tasks, press any key to close it. 
-------------------------------------------------------------------

Interestingly, I attempted to mount a volume in a MySQL container directly via the board terminal (without using Visual Studio Code), and it worked seamlessly without any issues.

I would greatly appreciate your guidance on resolving this issue. Let me know if you need more information about the project.

Thank you in advance for your time and support

docker-compose.yml (678 Bytes)
Program.cs (958 Bytes)

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

Thank you for reaching out with your question. It sounds like you’re encountering a permission issue when trying to mount a volume in your Docker container on Torizon, specifically when using Visual Studio Code. Let’s go through some steps to help resolve this issue:

  1. User Permissions: Ensure that the ‘torizon’ user, which is the default user in Torizon containers, has the necessary permissions to access the directory where the volume is mounted. The ‘torizon’ user should be part of the appropriate groups that allow access to the required resources.

  2. Volume Configuration: Double-check your docker-compose.yml file to ensure that the volume is correctly defined and mounted. The volume should be specified in the volumes section and properly mapped to the container path where your application expects to write the log file.

  3. File System Permissions: On the host system, verify that the directory used for the volume has the correct permissions set to allow the ‘torizon’ user to read and write. You can adjust these permissions using chmod and chown commands as needed.

  4. Visual Studio Code vs. Terminal: Since you mentioned that mounting a volume works when done directly via the terminal, but not through Visual Studio Code, there might be differences in the environment or user context. Ensure that Visual Studio Code is running with the same user permissions and environment settings as when you execute commands directly in the terminal.

  5. Avoid Running as Root: While it might be tempting to run the container as root to bypass permission issues, it’s generally not recommended due to security concerns. Instead, focus on configuring the ‘torizon’ user correctly.

By following these steps, you should be able to resolve the permission errors and successfully mount the volume for persistent storage of your log file. If the issue persists, double-check the Docker and file system configurations for any discrepancies.

I hope this helps! If you have any more questions, feel free to ask.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Torizon VS Code Extension run debug error 544 and 23 on rsync step.

Hello @J.Gadhiya,

The problem you are encountering seems to be caused by the following scenario:

  • The volume is created with ownership of the root user (uid: 0) by the Docker Daemon
  • The container runs with the torizon user (uid: 1000)

With this, the container has no permission to access the volume.
To avoid this problem, you can simply configure the volume as a bind-mount, in a custom path:

volumes:
  logvolume:
    driver: local
    driver_opts:
      type: none
      device: /home/torizon/logvolume
      o: bind,uid=1000,gid=1000

Please let me know if this works for you.

Best Regards,
Bruno

Thank you @bruno.tx

I tried your solution, but unfortunately, the outcome remains unchanged, and the same error persists.

I have attached the image below for more details.

Let me know if you more information from myside to help solve the error.

Thank you in advance.

Best regards,
Jenis

Hello @J.Gadhiya,

This error is caused by the location of the log directory inside the container.
As the volume is mounted to /home/torizon/app/logs, the /home/torizon/app folder is created with incorrect permissions.

Can you use another path within the container such as /applogs?
By doing so you should avoid this problem.

Best Regards,
Bruno

Hello @bruno.tx ,

Thank you very much for the solution. It finally works.

Best regards,
Jenis

Hello @J.Gadhiya,

That is good to know, thanks for the update!

Best Regards,
Bruno