Suggestions for running the same code in two containers

I have two USB cameras that I want to read video frames from and send to another computer. While it might be somewhat easier to coordinate the synchronization of the two cameras from a single executable given that the cameras are different communication failure modes.

When I say different failure modes, I mean that one camera might not fully work until we reopen and flush it several times, and the other camera is then waiting. Or a camera will suddenly stop responding, possibly resulting in a failure with the second camera while the code tries to re-establish communications with the first camera.

So while we try to figure out the root causes, and fix the underlying problems we are stuck with a very unstable system when we could have a somewhat stable system. Trade-offs…

I was wondering if there are any suggestions on how best to deploy and run two containers running basically the same code on the same device.

My first thought is to just duplicate the executable code and dockerfile.templates to create identical containers and use service variables or the container names to distinguish between them. Container1 would work with Camera1, Container2 with Camera2. This requires 2x the build time and 2x deployment time.

The second idea is to have one container hold the executable code, and to rsync it to a shared volume on startup. Then both containers can run the same code from the shared volume. 1x build time, 1x deployment time, maybe 1.5x boot time after a deployment.

Hi there.

I would duplicate the services in your docker-compose.yml but use the same container for both and simply override the CMD or ENV from the compose file to do the job. Something like this:

version: "2"
  services:
    camera1:
      build: ./mjpg-streamer
      privileged: true
      expose: 8080
      command: ./start.sh /dev/video0

    camera2:
      build: ./mjpg-streamer
      privileged: true
      expose: 8081
      command: ./start.sh /dev/video1

This means that the build server will build it for the first service, and then just use the cached build for the second one.

Hope this helps,
James.

Ah, looks like I got tripped up.
Lesson: “don’t be confused by the source directory name vs the docker container name”
Thanks for the solution!

My pleasure. Good luck with your project!