Hierarchy for Docker Files / "docker-compose up" issue — Question re: Chapter 2 of Django for Professionals

129 views
Skip to first unread message

Stephanie Goulet

unread,
Sep 8, 2022, 1:27:46 PM9/8/22
to Django users
Hi all, any help would be appreciated:

Question:
  1. In the below screenshot of VSC, are the last six files all in the right hierarchical place? In other words, should any of those be within either the "django_project" or "pages" folders? If so, which files should go in which level folder?
    Screen Shot 2022-09-08 at 1.13.36 PM.png

Context:
  • I'm new to this 
  • To learn, I went through the book Django for Beginners and am now working through Django for Professionals
  • I'm on page 29 of Chapter 2: Docker Hello, World! in the Django for Professionals PDF
  • It seems like I successfully did the "docker build ." command, but I'm running into trouble with the "docker-compose up" command. It's giving some traceback errors and a line that says "ModuleNotFoundError: No module named 'django_project'" which is why I suspect that I may have saved some of the files in the wrong place (maybe all of them belong in the 'django_project' folder?).
Thank you in advance!

Best,
Stephanie

Bhuvnesh Sharma

unread,
Sep 8, 2022, 4:50:28 PM9/8/22
to Django users
hi Stephanie,

Can you post the screenshot of your dockerfile?

Francisco Valadares

unread,
Sep 8, 2022, 4:50:39 PM9/8/22
to django...@googlegroups.com
  Hello Stephanie,

All the last six files can stay where they are (no problem). Observer if the commands in the Dockerfile file are copying the module(django_project) into the image. After you start the containner(docker-compose up) you could acess it with "docker exec -it <name container> sh".

How is your dockerfile and your .dockerignore?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2e1368cf-cee9-4aac-a74b-d727094b4f36n%40googlegroups.com.

Stephanie Goulet

unread,
Sep 8, 2022, 5:19:36 PM9/8/22
to django...@googlegroups.com
Thanks so much, Francisco. I'm doing something wrong that makes the "docker-compose up" not work to begin with. More detail, including the traceback text below:

Dockerfile & .dockerignore match the text in Ch 2 of the book Django for Professionals; here they are just in case that's helpful:
Screen Shot 2022-09-08 at 5.09.33 PM.png
Screen Shot 2022-09-08 at 5.10.32 PM.png

Traceback text:

(.venv) stephaniegoulet@Stephanies-MacBook-Pro ch2-hello % docker-compose up

Creating network "code2_default" with the default driver

Creating code2_web_1 ... done

Attaching to code2_web_1

web_1  | Traceback (most recent call last):

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 414, in run_from_argv

web_1  |     self.execute(*args, **cmd_options)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 74, in execute

web_1  |     super().execute(*args, **options)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 460, in execute

web_1  |     output = self.handle(*args, **options)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 81, in handle

web_1  |     if not settings.DEBUG and not settings.ALLOWED_HOSTS:

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/conf/__init__.py", line 87, in __getattr__

web_1  |     self._setup(name)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/conf/__init__.py", line 74, in _setup

web_1  |     self._wrapped = Settings(settings_module)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/conf/__init__.py", line 183, in __init__

web_1  |     mod = importlib.import_module(self.SETTINGS_MODULE)

web_1  |   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module

web_1  |     return _bootstrap._gcd_import(name[level:], package, level)

web_1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import

web_1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load

web_1  |   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked

web_1  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

web_1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import

web_1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load

web_1  |   File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked

web_1  | ModuleNotFoundError: No module named 'django_project'

web_1  | 

web_1  | During handling of the above exception, another exception occurred:

web_1  | 

web_1  | Traceback (most recent call last):

web_1  |   File "/code2/manage.py", line 22, in <module>

web_1  |     main()

web_1  |   File "/code2/manage.py", line 18, in main

web_1  |     execute_from_command_line(sys.argv)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line

web_1  |     utility.execute()

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute

web_1  |     self.fetch_command(subcommand).run_from_argv(self.argv)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/core/management/base.py", line 427, in run_from_argv

web_1  |     connections.close_all()

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 212, in close_all

web_1  |     for alias in self:

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/connection.py", line 73, in __iter__

web_1  |     return iter(self.settings)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/functional.py", line 49, in __get__

web_1  |     res = instance.__dict__[self.name] = self.func(instance)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/connection.py", line 45, in settings

web_1  |     self._settings = self.configure_settings(self._settings)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/db/utils.py", line 148, in configure_settings

web_1  |     databases = super().configure_settings(databases)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/utils/connection.py", line 50, in configure_settings

web_1  |     settings = getattr(django_settings, self.settings_name)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/conf/__init__.py", line 87, in __getattr__

web_1  |     self._setup(name)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/conf/__init__.py", line 74, in _setup

web_1  |     self._wrapped = Settings(settings_module)

web_1  |   File "/usr/local/lib/python3.10/site-packages/django/conf/__init__.py", line 183, in __init__

web_1  |     mod = importlib.import_module(self.SETTINGS_MODULE)

web_1  |   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module

web_1  |     return _bootstrap._gcd_import(name[level:], package, level)

web_1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import

web_1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load

web_1  |   File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked

web_1  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

web_1  |   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import

web_1  |   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load

web_1  |   File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked

web_1  | ModuleNotFoundError: No module named 'django_project'

code2_web_1 exited with code 1

(.venv) stephaniegoulet@Stephanies-MacBook-Pro ch2-hello % 





You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/ILI31w5H_QQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA-J3id6ZLCyONOqNx2Tdbyv3vR_g%3DBpYt-PEzTnGKqbV%2BTJTQ%40mail.gmail.com.

Francisco Valadares

unread,
Sep 8, 2022, 10:29:42 PM9/8/22
to django...@googlegroups.com
Hi Stephanie,


It may be that the error is related to the dependencies that your project needs.

Looking at your dockerfile I see that you are not loading the dependencies inside the WORKDIR /code2

Example:
...
WORKDIR /code2
COPY requirements.txt /code2/
RUN pip install -r requirements.txt
COPY .  /code2/
....



Stephanie Goulet

unread,
Sep 12, 2022, 1:28:06 PM9/12/22
to django...@googlegroups.com
Isn't that the same as what's already listed under the "# Install dependencies" and "# Copy project" notes in the Dockerfile?

I was looking online and it seems like this error is typically for when Django isn't installed, but I checked that it is installed in the .venv for this project, so I'm still not sure why it's happening.


Stephanie Goulet

unread,
Sep 28, 2022, 11:46:33 AM9/28/22
to django...@googlegroups.com
Any other thoughts on this? I feel like I could be missing something obvious.

Thanks again all!

Abdul Qoyyuum Haji Abdul Kadir

unread,
Sep 29, 2022, 3:20:53 AM9/29/22
to django...@googlegroups.com
Can you also share your docker-compose.yml file as well? It seems to be calling your django_project folder but can't seem to find it, even though the Dockerfile clearly shows that its copied.



--
Abdul Qoyyuum Haji Abdul Kadir
about.me/qoyyuum

Stephanie Goulet

unread,
Sep 29, 2022, 11:16:48 AM9/29/22
to Django users
Thanks for taking a look, Abdul; the docker-compose.yml file is below:
Screen Shot 2022-09-29 at 11.16.04 AM.png

subin

unread,
Oct 2, 2022, 4:16:17 PM10/2/22
to django...@googlegroups.com
Hi there! We just wanted to let you know we received your message and will be in touch before our offices close at

subin

unread,
Oct 2, 2022, 4:41:26 PM10/2/22
to django...@googlegroups.com
Thank you for your recent purchase from ! Please contact us if you have any questions or visit our website:

Stephanie Goulet

unread,
Oct 12, 2022, 11:18:00 AM10/12/22
to django...@googlegroups.com
I didn’t purchase anything, but if anyone has any other insight into this I’d be grateful. 

If not, I think I’m just going to try to start over and hope for the best. I just wish I understood where I’m going wrong. 

Thanks again,
Stephanie 

Reply all
Reply to author
Forward
0 new messages