Why does Django run server hang when using docker-compose up? - django

When I run docker-compose up, Django starts to load. It goes thru the about four steps. After it does a system check and identifies (0 issues), it stops at displaying the current date and time. This is the point where it just hangs. Nothing else happens.
C:\Users\********\Desktop\code\hello>docker-compose up
Creating hello_web_1 ... done
Attaching to hello_web_1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 | System check identified no issues (0 silenced).
web_1 | August 21, 2019 - 17:33:11
When I do docker-compose down, the system exits Gracefully(lol). Then I run docker-compose logs and it shows the correct info:
C:\Users\********\Desktop\code\hello>docker-compose logs
Attaching to hello_web_1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 | System check identified no issues (0 silenced).
web_1 | August 21, 2019 - 17:36:44
web_1 | Django version 2.2.3, using settings 'hello_project.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 | System check identified no issues (0 silenced).
web_1 | August 21, 2019 - 17:55:22
web_1 | Django version 2.2.3, using settings 'hello_project.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
Here is what my Dockerfile and docker-compose.yml look like:
#Dockerfile:
#Pull base image
From python:3.7-slim
#Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
#Set work directory
WORKDIR /code
#Install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system
#Copy project
COPY . /code/
#*docker-compose.yml:
web:
build: .
command: python /code/manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"```
note I'm using version 1 of docker-compose, that's why my web service is at the root of the file. I also omitted the version per Docker documentation.

Related

IP error: Django app not deploying with docker

I am new to Docker so I'm probably missing something obvious but here goes. I am trying to test a simple Django app with docker postgres. All I want right now is to verify that the home page is working on localhost. Debug output window gives me the following:
web_1 | System check identified no issues (0 silenced).
web_1 | April 28, 2020 - 17:06:23
web_1 | Django version 3.0.5, using settings 'app.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
However when I go to 0.0.0.0:8000 I get an error that says the site can't be reached
"The webpage at http://0.0.0.0:8000/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
Here is my docker-compose.yml:
version: '3.7'
services:
web:
build: .
command: python /app/manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- 8000:8000
depends_on:
- db
db:
image: "postgres:latest"
ports:
- "5432:5432"
environment:
- "POSTGRES_HOST_AUTH_METHOD=trust"
Here is my dockerfile:
# Pull base image
FROM python:3.8
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /app
# Install dependencies
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Copy project
COPY . /app/
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Would greatly appreciate any insight or help with troubleshooting. Because there are no errors in the debug window I'm not really sure where to start.
Thanks!
Had the same issue. Solved it by using Iain Shelvington's comment:
Try http://localhost:8000/ or http://127.0.0.1:8000/
Apparently 0.0.0.0 in the Dockerfile maps to localhost in the browser.

Setting up Django with docker

I am tried setting up django using docker but I am getting this error.
I have set up my Dockerfile and the docker-compose.yml.
docker-compose.yml
version: "3"
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /code/
This is the error I am getting.
Watching for file changes with StatReloader
web_1 | Exception in thread django-main-thread:
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner
I think This particular error was fixed in django 2.1
You'll want to upgrade your requirements to be django>=2.1 to ensure you get this new version.
The comments on the commit indicate that this patch will not be backported to django 1.11.x which does not support python3
after change django version re-ran docker-compose build.
Per the FAQ, Django 1.11.x is not compatible with Python 3
Django 1.11.x reached end of mainstream support on December 2, 2017
and it receives only data loss and security fixes until its end of
life.

Django runserver on Docker does not respond when opened in the browser

I am just a beginner at this
So when I run
sudo docker-compose run web python manage.py runserver
it shows
Starting thirddj_db_1 ... done
usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144:
UserWarning: The psycopg2 wheel package will be renamed from release
2.8; in order to keep installing from binary please use "pip install
psycopg2-binary" instead. For details see:
<http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py:144:
UserWarning: The psycopg2 wheel package will be renamed from release
2.8; in order to keep installing from binary please use "pip install
psycopg2-binary" instead. For details see:
<http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Performing system checks...
System check identified no issues (0 silenced).
April 11, 2018 - 19:15:59
Django version 1.11.12, using settings 'composeexample.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
And then when I opened it in my browser, it shows the site cant be reached
But when i run
docker-compose up
it shows
web_1 | /usr/local/lib/python3.6/site-
packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel
package will be renamed from release 2.8; in order to keep installing
from binary please use "pip install psycopg2-binary" instead. For
details see: <http://initd.org/psycopg/docs/install.html#binary-
install-from-pypi>.
web_1 | """)
web_1 | /usr/local/lib/python3.6/site-
packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel
package will be renamed from release 2.8; in order to keep installing
from binary please use "pip install psycopg2-binary" instead. For
details see: <http://initd.org/psycopg/docs/install.html#binary-
install-from-pypi>.
web_1 | """)
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | April 11, 2018 - 19:21:41
web_1 | Django version 1.11.12, using settings
'composeexample.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
And then when I opened it in my browser, it works
so i want to know Why sudo docker-compose run web python manage.py runserver is not working and what is the difference between both commands.
and here is my docker-compose file
version: '3'
services:
db:
image: postgres
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
When you run the web container it's necessary run command with the service's ports enabled and mapped to the host.
Try this:
sudo docker-compose run --service-ports web python manage.py runserver

Foreman start only has one line for Django and heroku

I install the heroku toolbelt from the website and use pip to install django toolbelt on both mac and ubuntu vm copy.
Both of them only return one line when using foreman start:
Procfile:
web: gunicorn hero.wsgi
foreman start:
23:44:46 web.1 | started with pid 4382
Ctrl+C and I got:
23:47:36 system | sending SIGTERM to all processes
23:47:36 web.1 | terminated by SIGTERM
I have read about the https://github.com/ddollar/foreman/wiki/Missing-Output
and did:
script.py:
PYTHONUNBUFFERED=True
and run it with python -u script.py
What am I doing wrong? Any advice will be appreciated.

Heroku Django Gunicorn 'Foreman Start' error

I'm working through the Heroku's Django tutorial and I got all the way down to 'Using a different WSIG server'.
When I try to use gunicorn I get the following error:
requirements.txt
Django==1.4.1
distribute==0.6.28
dj-database-url==0.2.1
psycopg2==2.4.5
gunicorn==0.14.6
Procfile
web: gunicorn djtut.wsgi -b 0.0.0.0:$PORT
(venv) C:\Users\xxxx\Documents\Python\djtut>foreman check
valid procfile detected (web)
(venv) C:\Users\xxxx\Documents\Python\djtut>foreman start
10:53:05 web.1 | started with pid 5652
10:53:06 web.1 | exited with code 1
10:53:06 web.1 | Traceback (most recent call last):
10:53:06 system | sending SIGKILL to all processes
10:53:06 | File "C:\Users\xxxx\Documents\Python\djtut\venv\Scripts\
gunicorn-script.py", line 9, in <module>
(venv) C:\Users\xxxxx\Documents\Python\djtut>
Works fine using the dev server on Heroku. I'm on Windows 7. Any ideas? I suspect it is an OS issue?
thanks,
AP
Unfortunately, Gunicorn doesn't work on Windows.