winget.pro icon indicating copy to clipboard operation
winget.pro copied to clipboard

Path Issues while building the Container

Open excelsi opened this issue 11 months ago • 3 comments

There are some path issues in the Dockerfile that appear at the docker compose up.

One issue was that the requirements folder with the base-full.txt was not in the /run/docker folder which i fixed by copying this folder from the top level to the /run/docker folder.

The other path issue shows up some steps later:

[+] Building 15.5s (10/11)                                                                               docker:default
 => [django internal] load build definition from Dockerfile                                                        0.1s
 => => transferring dockerfile: 32B                                                                                0.0s
 => [django internal] load .dockerignore                                                                           0.2s
 => => transferring context: 34B                                                                                   0.0s
 => [django internal] load metadata for docker.io/library/python:3.9                                               0.8s
 => [django 1/7] FROM docker.io/library/python:3.9@sha256:5c72dd8986db8c289ad1a6514319c144ed8f72c6dd702873c435844  0.0s
 => [django internal] load build context                                                                           0.1s
 => => transferring context: 908B                                                                                  0.0s
 => CACHED [django 2/7] WORKDIR /srv                                                                               0.0s
 => [django 3/7] COPY . .                                                                                          0.1s
 => [django 4/7] RUN mkdir `dirname /srv/db/db.sqlite3`                                                            0.6s
 => [django 5/7] RUN pip install --no-cache-dir -Ur requirements/base-full.txt                                    13.0s
 => ERROR [django 6/7] RUN python manage.py collectstatic --noinput                                                0.6s
------
 > [django 6/7] RUN python manage.py collectstatic --noinput:
0.580 python: can't open file '/srv/manage.py': [Errno 2] No such file or directory
------
failed to solve: executor failed running [/bin/sh -c python manage.py collectstatic --noinput]: exit code: 2

This i also tried to fix by copying the manage.py to different locations and/or changing the WORKDIR location. After removing the WORKDIR completly i stucked at this:

root@SRV-CON1:/home/wgpro/run/docker# docker compose up
[+] Building 16.1s (9/10)                                                                                docker:default
 => [django internal] load build definition from Dockerfile                                                        0.1s
 => => transferring dockerfile: 416B                                                                               0.0s
 => [django internal] load .dockerignore                                                                           0.1s
 => => transferring context: 34B                                                                                   0.0s
 => [django internal] load metadata for docker.io/library/python:3.9                                               1.0s
 => [django internal] load build context                                                                           0.1s
 => => transferring context: 937B                                                                                  0.0s
 => CACHED [django 1/6] FROM docker.io/library/python:3.9@sha256:5c72dd8986db8c289ad1a6514319c144ed8f72c6dd702873  0.0s
 => [django 2/6] COPY . .                                                                                          0.2s
 => [django 3/6] RUN mkdir `dirname /srv/db/db.sqlite3`                                                            0.6s
 => [django 4/6] RUN pip install --no-cache-dir -Ur requirements/base-full.txt                                    13.3s
 => ERROR [django 5/6] RUN python manage.py collectstatic --noinput                                                0.8s
------
 > [django 5/6] RUN python manage.py collectstatic --noinput:
0.673 Traceback (most recent call last):
0.673   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 237, in fetch_command
0.674     app_name = commands[subcommand]
0.674 KeyError: 'collectstatic'
0.674
0.674 During handling of the above exception, another exception occurred:
0.674
0.674 Traceback (most recent call last):
0.674   File "//manage.py", line 22, in <module>
0.674     main()
0.674   File "//manage.py", line 18, in main
0.674     execute_from_command_line(sys.argv)
0.674   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
0.674     utility.execute()
0.674   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
0.674     self.fetch_command(subcommand).run_from_argv(self.argv)
0.674   File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 244, in fetch_command
0.674     settings.INSTALLED_APPS
0.674   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
0.674     self._setup(name)
0.674   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
0.674     self._wrapped = Settings(settings_module)
0.674   File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
0.674     mod = importlib.import_module(self.SETTINGS_MODULE)
0.674   File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
0.674     return _bootstrap._gcd_import(name[level:], package, level)
0.674   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
0.674   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
0.674   File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
0.674   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
0.674   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
0.674   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
0.674   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
0.675 ModuleNotFoundError: No module named 'core'
------
failed to solve: executor failed running [/bin/sh -c python manage.py collectstatic --noinput]: exit code: 1

Would be nice if you can correct this. Thanks!

excelsi avatar Mar 30 '24 19:03 excelsi

I believe you need to do docker-compose up, not docker compose up.

mherrmann avatar Apr 01 '24 05:04 mherrmann

Thanks! I could now successfully start the build with docker-compose but then i got an permission error executing the start.sh script:

Building django
Sending build context to Docker daemon  12.87MB
Step 1/12 : FROM python:3.9
 ---> 7ef94ac333fa
Step 2/12 : ENV DEBUG=False
 ---> Using cache
 ---> a04870408315
Step 3/12 : ENV HOST_NAME=*
 ---> Using cache
 ---> aa2edea15886
Step 4/12 : ENV SQLITE_DB_FILE=/srv/db/db.sqlite3
 ---> Using cache
 ---> 263977cade5b
Step 5/12 : WORKDIR /srv
 ---> Using cache
 ---> 7530f3f5ba1d
Step 6/12 : COPY . .
 ---> d545560e4e52
Step 7/12 : RUN mkdir `dirname $SQLITE_DB_FILE`
 ---> Running in c9ce1196f196
Removing intermediate container c9ce1196f196
 ---> 23efbfe12f5f
Step 8/12 : RUN pip install --no-cache-dir -Ur requirements/base-full.txt
 ---> Running in 4b3486ce7e4e
Collecting django-suit@ https://github.com/lumocodes/django-suit/archive/suit-0.2.28-for-django3.1.zip
  Downloading https://github.com/lumocodes/django-suit/archive/suit-0.2.28-for-django3.1.zip
     - 713.7 kB 9.7 MB/s 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting asgiref==3.7.2
  Downloading asgiref-3.7.2-py3-none-any.whl (24 kB)
Collecting boto3==1.28.22
  Downloading boto3-1.28.22-py3-none-any.whl (135 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 135.8/135.8 kB 6.7 MB/s eta 0:00:00
Collecting botocore==1.31.24
  Downloading botocore-1.31.24-py3-none-any.whl (11.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.1/11.1 MB 20.9 MB/s eta 0:00:00
Collecting Django==3.2.20
  Downloading Django-3.2.20-py3-none-any.whl (7.9 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.9/7.9 MB 41.8 MB/s eta 0:00:00
Collecting django-storages==1.13.2
  Downloading django_storages-1.13.2-py3-none-any.whl (46 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.7/46.7 kB 203.1 MB/s eta 0:00:00
Collecting djangorestframework==3.14.0
  Downloading djangorestframework-3.14.0-py3-none-any.whl (1.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 62.9 MB/s eta 0:00:00
Collecting gunicorn==20.1.0
  Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 79.5/79.5 kB 65.2 MB/s eta 0:00:00
Collecting jmespath==1.0.1
  Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)
Collecting python-dateutil==2.8.2
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 103.8 MB/s eta 0:00:00
Collecting pytz==2023.3
  Downloading pytz-2023.3-py2.py3-none-any.whl (502 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.3/502.3 kB 192.6 MB/s eta 0:00:00
Collecting s3transfer==0.6.1
  Downloading s3transfer-0.6.1-py3-none-any.whl (79 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 79.8/79.8 kB 22.2 MB/s eta 0:00:00
Collecting six==1.16.0
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting sqlparse==0.4.4
  Downloading sqlparse-0.4.4-py3-none-any.whl (41 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.2/41.2 kB 181.3 MB/s eta 0:00:00
Collecting typing_extensions==4.7.1
  Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting urllib3==1.26.16
  Downloading urllib3-1.26.16-py2.py3-none-any.whl (143 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 143.1/143.1 kB 87.3 MB/s eta 0:00:00
Requirement already satisfied: setuptools>=3.0 in /usr/local/lib/python3.9/site-packages (from gunicorn==20.1.0->-r requirements/base-full.txt (line 10)) (58.1.0)
Building wheels for collected packages: django-suit
  Building wheel for django-suit (setup.py): started
  Building wheel for django-suit (setup.py): finished with status 'done'
  Created wheel for django-suit: filename=django_suit-0.2.28-py2.py3-none-any.whl size=402406 sha256=3105d24dc32afa4c2f481fa8f0b2f4775948c9bc3885644399772efed953f4af
  Stored in directory: /tmp/pip-ephem-wheel-cache-dsoqbr0c/wheels/71/16/5e/b85144fb0c83258c6a8e53f1740b003beda3d95688964c86fb
Successfully built django-suit
Installing collected packages: pytz, django-suit, urllib3, typing_extensions, sqlparse, six, jmespath, gunicorn, python-dateutil, asgiref, Django, botocore, s3transfer, djangorestframework, django-storages, boto3
Successfully installed Django-3.2.20 asgiref-3.7.2 boto3-1.28.22 botocore-1.31.24 django-storages-1.13.2 django-suit-0.2.28 djangorestframework-3.14.0 gunicorn-20.1.0 jmespath-1.0.1 python-dateutil-2.8.2 pytz-2023.3 s3transfer-0.6.1 six-1.16.0 sqlparse-0.4.4 typing_extensions-4.7.1 urllib3-1.26.16
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 23.0.1 -> 24.0
[notice] To update, run: pip install --upgrade pip
Removing intermediate container 4b3486ce7e4e
 ---> 4221d8f62d07
Step 9/12 : RUN python manage.py collectstatic --noinput
 ---> Running in 18c34f6788c7
Found another file with the destination path 'admin/css/forms.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.

211 static files copied to '/srv/static'.
Removing intermediate container 18c34f6788c7
 ---> 1db7c4ae9e57
Step 10/12 : EXPOSE 8000
 ---> Running in de0b9fbb842d
Removing intermediate container de0b9fbb842d
 ---> 0c20f5a2b533
Step 11/12 : RUN chmod +x /srv/run/docker/start.sh
 ---> Running in ecbe4ec54b8a
chmod: cannot access '/srv/run/docker/start.sh': No such file or directory
The command '/bin/sh -c chmod +x /srv/run/docker/start.sh' returned a non-zero code: 1
ERROR: Service 'django' failed to build : Build failed
root@SRV-CON1:/home/wgpro/run/docker# exit
logout
PS C:\Users\testadmin> notepad
PS C:\Users\testadmin> wsl --distribution debian
root@SRV-CON1:/mnt/c/Users/testadmin# cd /home/wgpro/run/docker/
root@SRV-CON1:/home/wgpro/run/docker# ./docker-compose up
Building django
Sending build context to Docker daemon  12.87MB
Step 1/12 : FROM python:3.9
 ---> 7ef94ac333fa
Step 2/12 : ENV DEBUG=False
 ---> Using cache
 ---> a04870408315
Step 3/12 : ENV HOST_NAME=*
 ---> Using cache
 ---> aa2edea15886
Step 4/12 : ENV SQLITE_DB_FILE=/srv/db/db.sqlite3
 ---> Using cache
 ---> 263977cade5b
Step 5/12 : WORKDIR /srv
 ---> Using cache
 ---> 7530f3f5ba1d
Step 6/12 : COPY . .
 ---> Using cache
 ---> d545560e4e52
Step 7/12 : RUN mkdir `dirname $SQLITE_DB_FILE`
 ---> Using cache
 ---> 23efbfe12f5f
Step 8/12 : RUN pip install --no-cache-dir -Ur requirements/base-full.txt
 ---> Using cache
 ---> 4221d8f62d07
Step 9/12 : RUN python manage.py collectstatic --noinput
 ---> Using cache
 ---> 1db7c4ae9e57
Step 10/12 : EXPOSE 8000
 ---> Using cache
 ---> 0c20f5a2b533
Step 11/12 : RUN chmod + ./start.sh
 ---> Running in b61bc04f3c82
Removing intermediate container b61bc04f3c82
 ---> 96771085ba93
Step 12/12 : CMD ["./start.sh"]
 ---> Running in 05cce3a4402f
Removing intermediate container 05cce3a4402f
 ---> 10761dcd4ab3
Successfully built 10761dcd4ab3
Successfully tagged docker_django:latest
WARNING: Image for service django was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating docker_django_1 ... error

ERROR: for docker_django_1  Cannot start service django: OCI runtime create failed: container_linux.go:377: starting container process caused: exec: "./start.sh": permission denied: unknown

ERROR: for django  Cannot start service django: OCI runtime create failed: container_linux.go:377: starting container process caused: exec: "./start.sh": permission denied: unknown
ERROR: Encountered errors while bringing up the project.

I tried to execute docker-compose with sudo as suggested on some sites but this didn't help unfortunatley.

excelsi avatar Apr 13 '24 14:04 excelsi

I did make progress again and will report it in the next days

excelsi avatar Apr 15 '24 18:04 excelsi

Closing this due to inactivity.

mherrmann avatar Jun 27 '24 13:06 mherrmann