raspi-cam-srv icon indicating copy to clipboard operation
raspi-cam-srv copied to clipboard

Package it in Docker / `docker-compose.yml`

Open GamePlayer-8 opened this issue 10 months ago • 5 comments
trafficstars

Hello,

Any way that the project would have a docker-compose.yml for easy deployment?

GamePlayer-8 avatar Jan 24 '25 19:01 GamePlayer-8

Hi, thanks for this suggestion.

This is on my ToDo list since long.

signag avatar Feb 04 '25 13:02 signag

Hi, so far, my effort to containerize this application was not (yet?) successful. See picamera2 issue 1216 - picamera2 in Docker - Cannot allocate memory The issue is that cameras use CMA memory and I currently do not know how this can be allocated by Docker. (Just got the answer that Pi 5 does not use CMA but I/O MMU)

In the test application mentioned in Issue 1216 it is seen that it works for small image sizes but it fails for larger ones as for the Model 3 camera, even for just taking a photo, not to talk about video recording.

If this cannot be resolved, it is unlikely that containerizing raspiCamSrv can be successful.

Also, I did not find any Docker projects using picamera2, except for very specific ones and demo cases. If you know some, please tell me.

signag avatar Feb 25 '25 16:02 signag

Heya,

Have you tried adding:

    shm_size: '1gb'
    deploy:
      resources:
        limits:
          memory: '2g' # with zram if not enough memory

and see how it goes?

Also is dmesg printing anything special?

GamePlayer-8 avatar Feb 25 '25 22:02 GamePlayer-8

Hi thanks for your suggestion.

However, the result is the same as before, except for the error message

! picamera2-test Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.

Since docker info also reports

..
WARNING: No memory limit support
WARNING: No swap limit support

this is probably to be expected.

dmesg sais, among others:

cma: cma_alloc: linux,cma: alloc failed, req-size: 729 pages, ret: -12

cat /proc/meminfo shows:

...
CmaTotal:          65536 kB
CmaFree:           49056 kB

Since, according to the picamera2-manual ch. 8.3, the 12MP Model 3 image requires 48 MB, this will probably be the bottleneck.

I increased cma by replacing

dtoverlay=vc4-kms-v3d

with

dtoverlay=vc4-kms-v3d,cma-512

in /boot/firmware/config.txt

Now, after reboot, I have:

CmaTotal:         524288 kB
CmaFree:          507808 kB

Now, the Cannot allocate memory error is gone when running the docker container with the Model 3 camera and a 12MP image is created.

This looks promising. I'll continue trying

signag avatar Feb 28 '25 18:02 signag

Hi, if you like, you can try using Docker as described in Running raspiCamSrv as Docker Container

This has been added in V2.13.

Up to now, I have tested it on a Pi 5 and a Pi 4.

signag avatar Mar 07 '25 20:03 signag