Closed NoLandMen496 closed 2 years ago
Do you have a main
directory in /home/flasky/app
? Is there a __init__.py
inside this directory? Does this file have a main
variable in it? Since the import is failing, one of these questions must have a "no" answer. You can log in to your container to check these things using the docker exec
command.
Thanks for "wasting" time on this. Good questions. I have a main directory in /home/flasky/app
. But can't check for __init__.py
or main
variable because can't cd to main/: Permission denied
.
The odd thing about this is: I cloned your entire code (Dockerfile & all) and followed the commands in your book to the letter. No changes. Do you have another tip? If you run the 17d code on your side, in 2021, can you replicate the issue?
Terminal code to look inside the container:
$ docker commit 716bd1c028a3 debug/flasky
sha256:4107650b9e649674ec2cd2189e68fb9195adb2696323d12274d993e14702bd67
~/being-awesome/4_books_courses/courses/flask/2018-flask-web-dev/flasky-17d
$ docker run -it --rm --entrypoint sh debug/flasky
~ $ pwd
/home/flasky
~ $ ls
__pycache__ boot.sh flasky.py requirements
app config.py migrations venv
~ $ cd app/
~/app $ ls
__init__.py decorators.py fake.py static
api email.py main templates
auth exceptions.py models.py
~/app $ cd main/
sh: cd: can't cd to main/: Permission denied
~/app $ ls main/
ls: can't open 'main/': Permission denied
~/app $ ls -l
total 56
-rw-rw-r-- 1 root root 1124 Dec 29 16:44 __init__.py
drwx------ 2 root root 4096 Jul 20 09:41 api
drwx------ 2 root root 4096 Jul 20 09:41 auth
-rw-rw-r-- 1 root root 494 Jul 20 09:41 decorators.py
-rw-rw-r-- 1 root root 669 Jul 20 09:41 email.py
-rw-rw-r-- 1 root root 44 Jul 20 09:41 exceptions.py
-rw-rw-r-- 1 root root 1012 Jul 20 09:41 fake.py
drwx------ 2 root root 4096 Jul 20 09:41 main
-rw-rw-r-- 1 root root 12892 Jul 20 09:41 models.py
drwx------ 2 root root 4096 Jul 20 09:41 static
drwx------ 4 root root 4096 Jul 20 09:41 templates
~/app $
Have you done anything to change the default umask
setting on your system? This is what I get:
-rw-r--r-- 1 root root 1156 Jul 20 09:38 __init__.py
drwxr-xr-x 2 root root 4096 May 16 2021 __pycache__
drwxr-xr-x 3 root root 4096 Feb 1 2021 api
drwxr-xr-x 3 root root 4096 Jul 20 09:38 auth
-rw-r--r-- 1 root root 494 Dec 19 2020 decorators.py
-rw-r--r-- 1 root root 669 Dec 19 2020 email.py
-rw-r--r-- 1 root root 44 Feb 1 2021 exceptions.py
-rw-r--r-- 1 root root 1012 Dec 19 2020 fake.py
drwxr-xr-x 3 root root 4096 Jul 20 09:38 main
-rw-r--r-- 1 root root 12892 Feb 1 2021 models.py
drwxr-xr-x 2 root root 4096 Feb 1 2021 static
drwxr-xr-x 4 root root 4096 Feb 1 2021 templates
Note how all the files are readable by everybody. Your directories are only accessible to the root user.
Miguel you should receive an international award for best teacher 2021. The directory where I kept my files had the permissions completely out of wack. Nobody could read the files besides root. Created a new directory with the correct umask value and everything is hunky dory.
If folders can't be read of course imports will not work. Very obvious and simple, but only after you point it out.
1 - Problem
Miguel your book and github support are awesome and unique. Thanks. I cloned and used your code from 17d locally, built an image successfully, but I can't run the docker container because it shuts down due to an ImportError: cannot import name name 'main'.
My docker is
Docker version 20.10.12, build e91ed57
. I have used your exact code & dependencies so you can replicate the problem. You Dockerfile (maybe) has a error on env variableI tried with production and docker, the error was always the same.
The steps 2, 3 & 4 show the traces.
Step 2 - Image is built without errors
Step 3 - Container runs with no apparent error, but stops immediately
Step 4 - Docker logs say -- ImportError: cannot import name 'main'
Any ideas?