I
I
Ilya Koren2022-04-20 22:12:49
JavaScript
Ilya Koren, 2022-04-20 22:12:49

How to check if a file exists in a project if it is in another docker container?

Good afternoon!
Can you please tell me how to check the existence of a file in the project if it is in another docker container?
I am writing a function with jest tests and I want to display different messages depending on the existence of the file.
here is my code:

const doesExist = async () => {
      return fsPromises.access(path.resolve() + "/../button.png", fs.constants.R_OK | fs.constants.W_OK)
        .then(() => console.log("Файл существует");
        .catch(() => console.log("Файл отсутствует");
    }

At the moment path.resolve() + "/../button.png" is spelled incorrectly.
The function with tests is launched from the front container (frontend), and the file is located in another container (backend).
Accordingly, if you use path.resolve(), then "frontend" will return, and I need to go up to the directory above, and then to the backend. Hence the whole mess.
(PS in this case, catch always works, because the file is not found.)
Can I somehow check the existence of a file throughout the project, regardless of the container, for example, by name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romaro, 2022-04-21
@IlyaMalone

Containers have separate file systems, i.e. they can communicate with each other via docker-network. In theory, you need to implement the image presence API in the backend container and pull it from the second container.
Or move resources shared by containers to the host machine and mount a directory with these resources in both containers. Then they will have a common file system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question