How does Docker App Running Inside Container 1 should read file from Container 2 which is Volume Mounted to Host Machine

We have a setup like this.

Container 1 -> C# Web Application
Container 2 -> Redis Db (The dump file is volume mounted to host machine for persistence purpose)

There is a docker compose file to run both the containers together and link them under a single network. With this C# application is able to access Redis DB and all good.

Now we want to implement a feature in our application where the application should take periodic backup of RedisDb and upload it to Cloud. That is, copy the volume mounted dump file of Redis DB and upload it into cloud.

Is this possible to achieve? I am unable to find the details anywhere in the internet to know how an app running inside container 1 can access a volume mounted file of container 2.

Answer

You can mount the same redis persistence volume on Container 1 as well (for your purpose readonly mode is enough). then the dump.rdb file will be accessible to your c# application.

Example:

version: "3.9"
services:
  redis:
    image: redis
    volumes:
      - /redis_data_path_on_host:/usr/share/nginx/html
  app:
    image: app
    volumes:
      - /redis_data_path_on_host:/usr/share/nginx/html:ro

Leave a Reply

Your email address will not be published. Required fields are marked *