How do developers manage dependencies in Docker-based multi-service projects?

Hi everyone,

I am currently learning Docker and containerized development for the first time. I am working on a small multi-service project using Docker Compose (for example: API service, frontend service, database, and nginx).

My biggest difficulty so far is understanding how dependencies should be managed in Docker-based projects.

Each service has its own Dockerfile and sometimes its own dependency file (for example requirements.txt for Python services). However, I often encounter issues where the container fails to start because a dependency is missing or because of a version conflict between packages.

For example, sometimes I see errors like:

ModuleNotFoundError: No module named 'something'

or version-related issues caused by indirect dependencies that were installed automatically.

What confuses me is:

  1. How do developers usually decide which dependencies should be explicitly listed in files like requirements.txt ?
  2. Should we only list the packages we directly import in the code, or also include their indirect dependencies?
  3. What is the typical workflow professionals use to debug dependency issues inside Docker containers?
  4. In larger Docker Compose setups with multiple services, how do teams usually keep dependencies organized and avoid conflicts?

Since I am new to Docker and containerized development, I would really appreciate any advice or best practices used in real-world projects.

Thank you!

1 Like

If a module is not found you are probably not using the same python to which the modules were installed. For example system packages vs virtual environment.

The requirements file question is a general python development question. If you add only required packages and some dependencies are updated that could break a new installation (or new docker build). If you add all, you can temporarily remove the dependencies to download the latest and ā€œfreezeā€ the versions again. But I’m not a Python developer.

Regarding debugging, that also seems to be mostly Python development question, except that accessing a failing container is a little bit harder. You can always change the entrypoint or command to able to start an interactive shell in the container and run commands manually for debugging. but it all depends it the nature of the issue.

I don’t understand the 4th question.

Note that the general questions are not attractive to the community as it leads to a never ending conversation and debates. If you have specific questions you can expect more specific replies in separate topics for each specific question.

For learning generally, I can recommend guides like this