1

I am currently running a Dash (Flask) app in a Docker container that saves user data onto the filesystem within a folder called assets. In another container, I have a Python script called worker.py from where I want to delete a folder that is within the first container. How could I go about doing this? The directory structure is shown below:

(container1):
|- src
|  - app.py
|  - assets
|    - FolderIWantToDelete

(container2):
|- worker
|  - worker.py (the file I am running from)
|  - Dockerfile

I began by typing out shutil.rmtree("Path/To/Folder/I/Want/To/Delete") but got stuck as I believe you can't specify a path into container1 from container2, since Docker containers are isolated from one another.

A thought might be to send an http delete request to container1 from worker.py container2 specifying the delete function to use and path to the folder; however, I am not a web developer so this confuses me.

I can edit this post with more code/information if needed. Thanks for the help!

Solution: As pointed out by users below creating a shared volume within your docker-compose file and assigning it to both containers can solve this problem. Personally, I went with a different route, I removed container1 and ran worker.py from container2 as a thread that was made within app.py.

marxfh
  • 11
  • 2
  • You can use something like docker-compose and choose to share a directory between the two containers. Containers (with additional no settings applied) will have their own isolated filesystem. – flakes Apr 01 '22 at 20:53

1 Answers1

0

You can create a docker network and attack both containers onto it, in which case you can reference the other container's path by IMAGENAME://HOSTNAME/PATH_TO_FILE_TO_DELETE. Here is a guide on how to perform this using docker-compose

Daniel Al Mouiee
  • 1,111
  • 8
  • 11