How to add a new Django Project to the Existing sytem in Docker using yml

Hey Everyone :wave:
I am trying to add prininting_service to existing .yml configuration and i am getting this error.
Other Django services are working fine and i have just initialised the project with printing trying to connect to the volume.

2023-11-09 14:56:57 Traceback (most recent call last):
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv
2023-11-09 14:56:57     self.execute(*args, **cmd_options)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 74, in execute
2023-11-09 14:56:57     super().execute(*args, **options)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute
2023-11-09 14:56:57     output = self.handle(*args, **options)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 81, in handle
2023-11-09 14:56:57     if not settings.DEBUG and not settings.ALLOWED_HOSTS:
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 102, in __getattr__
2023-11-09 14:56:57     self._setup(name)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 89, in _setup
2023-11-09 14:56:57     self._wrapped = Settings(settings_module)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 217, in __init__
2023-11-09 14:56:57     mod = importlib.import_module(self.SETTINGS_MODULE)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
2023-11-09 14:56:57     return _bootstrap._gcd_import(name[level:], package, level)
2023-11-09 14:56:57   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2023-11-09 14:56:57   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2023-11-09 14:56:57   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2023-11-09 14:56:57 ModuleNotFoundError: No module named 'printing.settings'
2023-11-09 14:56:57 
2023-11-09 14:56:57 During handling of the above exception, another exception occurred:
2023-11-09 14:56:57 
2023-11-09 14:56:57 Traceback (most recent call last):
2023-11-09 14:56:57   File "/app/manage.py", line 22, in <module>
2023-11-09 14:56:57     main()
2023-11-09 14:56:57   File "/app/manage.py", line 18, in main
2023-11-09 14:56:57     execute_from_command_line(sys.argv)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
2023-11-09 14:56:57     utility.execute()
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute
2023-11-09 14:56:57     self.fetch_command(subcommand).run_from_argv(self.argv)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 425, in run_from_argv
2023-11-09 14:56:57     connections.close_all()
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 84, in close_all
2023-11-09 14:56:57     for conn in self.all(initialized_only=True):
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 76, in all
2023-11-09 14:56:57     return [
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 73, in __iter__
2023-11-09 14:56:57     return iter(self.settings)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__
2023-11-09 14:56:57     res = instance.__dict__[self.name] = self.func(instance)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 45, in settings
2023-11-09 14:56:57     self._settings = self.configure_settings(self._settings)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 148, in configure_settings
2023-11-09 14:56:57     databases = super().configure_settings(databases)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 50, in configure_settings
2023-11-09 14:56:57     settings = getattr(django_settings, self.settings_name)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 102, in __getattr__
2023-11-09 14:56:57     self._setup(name)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 89, in _setup
2023-11-09 14:56:57     self._wrapped = Settings(settings_module)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 217, in __init__
2023-11-09 14:56:57     mod = importlib.import_module(self.SETTINGS_MODULE)
2023-11-09 14:56:57   File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
2023-11-09 14:56:57     return _bootstrap._gcd_import(name[level:], package, level)
2023-11-09 14:56:57   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
2023-11-09 14:56:57   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
2023-11-09 14:56:57   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
2023-11-09 14:56:57 ModuleNotFoundError: No module named 'printing.settings'

This is .yml file

version: '3.8'

services:
  cartonprintingsystem:
    build: 
      context: ./cartonprintingsystem
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
    # volumes:
    #   - ./cartonprintingsystem:/app
    volumes:
      - carton-printing:/app 
    networks:
      - Carton

  inspection_service:
    build:
      context: ./inspection_service
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8001
    ports:
      - "8001:8001"
    volumes:
      - carton-printing:/app 
    environment:
      - DJANGO_SETTINGS_MODULE=inspection_service.settings
    networks:
      - Carton

  printing_service:
    build:
      context: ./printing
      dockerfile: Dockerfile
    command: python manage.py runserver 0.0.0.0:8002
    ports:
      - "8002:8002"
    volumes:
      - carton-printing:/app 
    environment:
      - DJANGO_SETTINGS_MODULE=printing.settings
    networks:
      - Carton

  phpMyAdmin:
    image: phpmyadmin
    environment:
      PMA_ARBITRARY: 1
    ports:
      - "9090:80"

  broker:
    image: confluentinc/cp-kafka:7.5.0
    container_name: broker
    ports:
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
      KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
      KAFKA_PROCESS_ROLES: broker,controller
      KAFKA_NODE_ID: 1
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@broker:29093
      KAFKA_LISTENERS: PLAINTEXT://broker:29092,CONTROLLER://broker:29093,PLAINTEXT_HOST://0.0.0.0:9092
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_LOG_DIRS: /tmp/kraft-combined-logs
      CLUSTER_ID: MkU3OEVBNTcwNTJENDM2Qk
    networks:
      - Carton

volumes:
  carton-printing:

networks:
  Carton:

It sounds to me like you’re adding new code here, you want to make sure that the volume is deleted before doing your docker compose.

Side note: Pay attention to the docs and do not use runserver as your means of running your project. Quoting directly rrom the docs:

DO NOT USE THIS SERVER IN A PRODUCTION SETTING.

Use gunicorn, or some other wsgi container, to run your application.

I attempted to verify if the issue persisted due to an existing volume by creating a new application. I initialized three Django projects with a new volume and network, yet the error persists.

What do your two Dockerfiles look like?

What is supposed to be stored in the volume? (You might want to dump its contents to verify that the data in it is where you’re expecting it to be.)
Note from the docker volume docs:

If you start a container which creates a new volume, and the container has files or directories in the directory to be mounted such as /app/ , Docker copies the directory’s contents into the volume. The container then mounts and uses the volume, and other containers which use the volume also have access to the pre-populated content.

Note that what it doesn’t say is that subsequent containers using that volume do not have their contents copied into the volume.

That’s a little more explicit in the tips section of the storage docs:

If you mount an empty volume into a directory in the container in which files or directories exist, these files or directories are propagated (copied) into the volume.

and

If you mount a bind mount or non-empty volume into a directory in the container in which some files or directories exist, these files or directories are obscured by the mount, …

What this means in practice is that only one of your containers will populate the volume. (This does seem to be a fairly common “gotcha” among people I know first working with docker compose.)