How to attach an external device (camera) to a container?

Hi there,
I have deployed a container with a simple flask app on Google Cloud. To attach an external device I would like to "add the --device flag" to my container, which can be achieved locally by doing something like this:

 

 

docker run --device=/dev/video0 my_image_name

 

 

Does anyone know how to do this on Google Cloud? How can I set "run configurations" like the above for my image on Cloud Run? Do I need to do this on Google Kubernetes Engine? Where can I get more information on this?
I would appreciate any help!

1 3 188
3 REPLIES 3

Hi @Roman-o-which 

Welcome to Google Cloud Community!

If this is running inside a VM instance, you need to have an additional disk wherein you can upload the files/folders that are needed by your container. You can look on this guide on how to upload files on your vm instance and this guide on adding disk for your instance.

I hope this information is helpful.

If you need further assistance, you can always file a ticket on our support team.

Thanks to @RonEtch for the response. I'd like to provide more context about my project: I'm working on deploying a Python Flask app on Google Cloud Run. In general, the deployment process is smooth, and the app runs from a Docker image. The app employs a computer vision model to detect and classify species of kangaroos, using either uploaded photos or the user's camera.

My goal is to enable access to the user's camera within the Docker image. Locally, this is achievable by adding the --device flag. However, when running the image on Google Cloud, particularly on Cloud Run, I don't have direct control over how the image is executed. Consequently, I'm exploring ways to access a device's camera from within a Docker image deployed on Google Cloud.

This won't work as you think it might.  When you are attaching the device and running the container locally, it works fine, because you are passing your webcam through directly to the container.  

When you are running on Cloud Run, you are not running on your local machine, there is no direct connectivity to the webcam, there is no local device you can map through.

Instead you will need to figure out a client side/browser mechanism to capture the users webcam and then stream that to the backend service in Cloud Run.  For example you could look into WebRTC to capture a users stream and pass it to a backend API via RTP/RTCP.  Though this is just one possible way and outside the scope of this forum.

If you don't need to to stream constantly, you could also look to a client side mechanism to capture a short video record and upload it to Google Cloud Storage and then trigger a Cloud Run service to process the data.  This would be technically much easier to achieve.

Just some options that come to mind, there are many ways you could approach this, but key is that when you are running in Cloud Run, this is completely remote from the users machine and so there is no direct access to hardware as there is when you are running locally.

All the best,

Alex

Top Labels in this Space