docker container built and running but not working - django

My name is omar. I have a docker image and container for a project that I have just created and ran. So i am currently trying to test it on my local machine before pushing it to an online environment. I built it with no previous cache and it build the new docker which is running online. Why is it not working in my browser. Here is what I have.
(MySplit) omars-mbp:mysplit omarjandali$ docker build --no-cache -t validation_test_1 .
Sending build context to Docker daemon 56.07MB
Step 1/7 : FROM python:3
---> 79e1dc9af1c1
Step 2/7 : WORKDIR users/
Removing intermediate container 7030351beb91
---> 30ac3f4ccbae
Step 3/7 : COPY requirements.txt ./
---> 57cbbd7335ab
Step 4/7 : EXPOSE 80
---> Running in 592407a176ff
Removing intermediate container 592407a176ff
---> 523945ea529f
Step 5/7 : RUN pip install -r requirements.txt
---> Running in 48347f772fbe
Collecting Django==1.11.5 (from -r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/18/2d/b477232dd619d81766064cd07ba5b35e956ff8a8c5c5d41754e0392b96e3/Django-1.11.5-py2.py3-none-any.whl (6.9MB)
Collecting gunicorn==19.7 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/96/4b/bc4bc2dad60defaa3f7d8590dc51331a225a5399380c161047c1224cd86d/gunicorn-19.7.0-py2.py3-none-any.whl (112kB)
Collecting django-localflavor==1.5.3 (from -r requirements.txt (line 3))
Downloading https://files.pythonhosted.org/packages/da/47/69e53f69fb50a38766aa929c1f81fd2e6315edc7f3945174ead24ffcf6df/django-localflavor-1.5.3.tar.gz (4.7MB)
Collecting synapse_pay_rest_native==3.1.1 (from -r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/43/27/b73d83dd50d4dfec1680d22896b800ddbb6bf8fb3f3a1755a916a6e4f732/synapse_pay_rest_native-3.1.1.tar.gz
Collecting pytz (from Django==1.11.5->-r requirements.txt (line 1))
Downloading https://files.pythonhosted.org/packages/dc/83/15f7833b70d3e067ca91467ca245bae0f6fe56ddc7451aa0dc5606b120f2/pytz-2018.4-py2.py3-none-any.whl (510kB)
Collecting requests (from synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
Collecting chardet<3.1.0,>=3.0.2 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
Collecting idna<2.7,>=2.5 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl (56kB)
Collecting urllib3<1.23,>=1.21.1 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
Collecting certifi>=2017.4.17 (from requests->synapse_pay_rest_native==3.1.1->-r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
Building wheels for collected packages: django-localflavor, synapse-pay-rest-native
Running setup.py bdist_wheel for django-localflavor: started
Running setup.py bdist_wheel for django-localflavor: finished with status 'done'
Stored in directory: /root/.cache/pip/wheels/36/41/a8/30c023fe29300f1a19d0520aaff1faf9e4c7ab176c53913ab5
Running setup.py bdist_wheel for synapse-pay-rest-native: started
Running setup.py bdist_wheel for synapse-pay-rest-native: finished with status 'done'
Stored in directory: /root/.cache/pip/wheels/33/93/7f/6bd8dd39a1c22e2ef85a259a45e603dff2b0ab4d6209a7a976
Successfully built django-localflavor synapse-pay-rest-native
Installing collected packages: pytz, Django, gunicorn, django-localflavor, chardet, idna, urllib3, certifi, requests, synapse-pay-rest-native
Successfully installed Django-1.11.5 certifi-2018.4.16 chardet-3.0.4 django-localflavor-1.5.3 gunicorn-19.7.0 idna-2.6 pytz-2018.4 requests-2.18.4 synapse-pay-rest-native-3.1.1 urllib3-1.22
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Removing intermediate container 48347f772fbe
---> 5749b63a2fef
Step 6/7 : COPY . .
---> 7754d9db1f38
Step 7/7 : CMD ["python", "manage.py", "runserver"]
---> Running in 362648ae0426
Removing intermediate container 362648ae0426
---> c26bf2de11b4
Successfully built c26bf2de11b4
Successfully tagged validation_test_1:latest
(MySplit) omars-mbp:mysplit omarjandali$ docker run -d -P validation_test_1:latest
b038c688ba4e681c03d8e093cf630a564d2f7cea27812b55dd0d1c33aa0f27b4
(MySplit) omars-mbp:mysplit omarjandali$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b038c688ba4e validation_test_1:latest "python manage.py ru…" 5 seconds ago Up 4 seconds 0.0.0.0:32768->80/tcp zealous_mcnulty
(MySplit) omars-mbp:mysplit omarjandali$
I have tried the following localhost:32768 and 127.0.0.1:32768 does anyone know why this is happening.
I have allowed all hosts in my django project.
dockerfile
FROM python:3
WORKDIR users/
COPY requirements.txt ./
EXPOSE 80
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver"]

This will be because Django's runserver accepts connections from 127.0.0.1 only by default and when you hit localhost:32768 from your browser the connection isn't coming from 127.0.0.1 / localhost, but from your actual host IP.
Change your CMD to:
CMD ["python", "manage.py", "runserver", "0.0.0.0:80"]

Related

Docker Django image running but not found on localhost

I am trying to run a Django docker image. The image itself is running in the command line without any errors. However when I go to the URL my image is hosted at, the web page is not found.
Below is my docker file I used to build the image
FROM python:3.6
MAINTAINER c15523957
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install libgdal-dev
RUN mkdir -p /usr/src/app
COPY requirements.txt /usr/src/app/
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN pip install --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Below is the command used to run the image
docker run -it -p8001:8000 c15523957/backendimage7
The console logs the message
System check identified no issues (0 silenced).
December 11, 2018 - 15:05:03
Django version 2.1.3, using settings 'backendproject.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
However when I go to the browser the web page is not found.
Note: When I run the Django application without the Docker image the webpage is seen. This is done with
python manage.py runserver
SOLUTION
I was using docker toolbox for windows. Instead of local dcker toolbox binds to the address 192.168.99.100 . So by going to port ....
192.168.99.100:8001
I was able to access my web page

Error greenlet docker build

everything good? I have a problem using docker build. This application has already been mounted on 2 other machines but every time this error occurs. Does anyone know what I should do to fix it. I have a windows 10 and im using Docker Toolbox.
I tried this answer here from the site without success:
Python module installation error: command 'gcc' failed with exit status 1
I followed the docking tutorial from docker's own website:
https://docs.docker.com/compose/django/#define-the-project-components
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
RUN pip3 install virtualenv
RUN virtualenv /code
ADD requirements.txt /code/
RUN python -m pip install -r requirements.txt --no-cache-dir
ADD . /code/
Error log:
PS C:\Users\ThinkPad\Documents\ChatBot> docker build -t backend .
Sending build context to Docker daemon 209.5MB
Step 1/9 : FROM python:3
---> ce54ff8f2af6
Step 2/9 : ENV PYTHONUNBUFFERED 1
---> Using cache
---> 5cefadc9e069
Step 3/9 : RUN mkdir /code
---> Using cache
---> 1dd0287bc4ba
Step 4/9 : WORKDIR /code
---> Using cache
---> 3790083599e1
Step 5/9 : RUN pip3 install virtualenv
---> Using cache
---> ddc61851cc43
Step 6/9 : RUN virtualenv /code
---> Using cache
---> fa9028959057
Step 7/9 : ADD requirements.txt /code/
---> a4b2b341f4f6
Step 8/9 : RUN python -m pip install -r requirements.txt --no-cache-dir
---> Running in fe0b99a3ecf4
Requirement already satisfied: pip==10.0.1 in /usr/local/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (10.0.1)
Collecting amqp==2.2.2 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/88/4a/8c45a882d842678963516ebd9cf584a4ded51af719234c3b696c2e884c60/amqp-2.2.2-py2.py3-none-any.whl (48kB)
Collecting billiard==3.5.0.3 (from -r requirements.txt (line 3))
Downloading https://files.pythonhosted.org/packages/82/55/76f4e786141b7174926cdffa7a155aeea316b729118fb48ec548f3c6754f/billiard-3.5.0.3-py3-none-any.whl (89kB)
Collecting celery==4.1.0 (from -r requirements.txt (line 4))
Downloading https://files.pythonhosted.org/packages/22/9b/88ef5cc7edf5d43215f383ae0a2b1cdeb33f5f07886386c7e4691b2eba0c/celery-4.1.0-py2.py3-none-any.whl (400kB)
Collecting Django==2.0.1 (from -r requirements.txt (line 5))
Downloading https://files.pythonhosted.org/packages/21/2a/3a0ec97b18d6e8d295142228f03604ac78ea6de05cf9bc3773a74f0b58bb/Django-2.0.1-py3-none-any.whl (7.1MB)
Collecting django-cors-headers==2.1.0 (from -r requirements.txt (line 6))
Downloading https://files.pythonhosted.org/packages/10/97/40b519badff93449706cd2cab3f328e1898e627bb218e3429c5581ad1932/django_cors_headers-2.1.0-py2.py3-none-any.whl
Collecting django-notifs==2.6.0 (from -r requirements.txt (line 7))
Downloading https://files.pythonhosted.org/packages/63/30/8b9b90d3aa47b3b50046eb202727730a6d9ba9b4bc45478ba35466e7662c/django-notifs-2.6.0.tar.gz
Collecting django-templated-mail==1.0.0 (from -r requirements.txt (line 8))
Downloading https://files.pythonhosted.org/packages/24/a8/9619c9a6fbe784c5d9c31283aeb2dd16c1f16902485b7c3f578b39ecd21b/django_templated_mail-1.0.0-py3-none-any.whl
Collecting djangorestframework==3.7.7 (from -r requirements.txt (line 9))
Downloading https://files.pythonhosted.org/packages/7c/0f/70957d583a9040c902b22dfab88323c1be61266eaddb1b3463a401004856/djangorestframework-3.7.7-py2.py3-none-any.whl (1.1MB)
Collecting djangorestframework-jwt==1.11.0 (from -r requirements.txt (line 10))
Downloading https://files.pythonhosted.org/packages/2b/cf/b3932ad3261d6332284152a00c3e3a275a653692d318acc6b2e9cf6a1ce3/djangorestframework_jwt-1.11.0-py2.py3-none-any.whlCollecting djoser==1.1.5 (from -r requirements.txt (line 11))
Downloading https://files.pythonhosted.org/packages/9f/cf/d985a0a453a02c018a68ea69de6c9482bbb345ec85037355601a0023525f/djoser-1.1.5-py3-none-any.whl
Collecting gevent==1.2.2 (from -r requirements.txt (line 12))
Downloading https://files.pythonhosted.org/packages/1b/92/b111f76e54d2be11375b47b213b56687214f258fd9dae703546d30b837be/gevent-1.2.2.tar.gz (3.1MB)
Collecting greenlet==0.4.12 (from -r requirements.txt (line 13))
Downloading https://files.pythonhosted.org/packages/be/76/82af375d98724054b7e273b5d9369346937324f9bcc20980b45b068ef0b0/greenlet-0.4.12.tar.gz (57kB)
Collecting kombu==4.1.0 (from -r requirements.txt (line 14))
Downloading https://files.pythonhosted.org/packages/62/a4/5d16954803224a1e451713293c2a028614099f5538cf626e1fdd7b438c86/kombu-4.1.0-py2.py3-none-any.whl (181kB)
Collecting pika==0.11.2 (from -r requirements.txt (line 15))
Downloading https://files.pythonhosted.org/packages/76/b4/0ada6918ac79ce4d8d45d0ba436ee21a1ef685047fb1dde4d2de0178b327/pika-0.11.2-py2.py3-none-any.whl (107kB)
Collecting PyJWT==1.6.1 (from -r requirements.txt (line 16))
Downloading https://files.pythonhosted.org/packages/31/8f/19c302aa9a391dd1fbd249362b749021b88d40fb59af0363939a2250afed/PyJWT-1.6.1-py2.py3-none-any.whl
Collecting pytz==2017.3 (from -r requirements.txt (line 17))
Downloading https://files.pythonhosted.org/packages/a3/7f/e7d1acbd433b929168a4fb4182a2ff3c33653717195a26c1de099ad1ef29/pytz-2017.3-py2.py3-none-any.whl (511kB)
Collecting simplejson==3.13.2 (from -r requirements.txt (line 18))
Downloading https://files.pythonhosted.org/packages/0d/3f/3a16847fe5c010110a8f54dd8fe7b091b4e22922def374fe1cce9c1cb7e9/simplejson-3.13.2.tar.gz (79kB)
Collecting six==1.11.0 (from -r requirements.txt (line 19))
Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting uwsgi==2.0.15 (from -r requirements.txt (line 20))
Downloading https://files.pythonhosted.org/packages/bb/0a/45e5aa80dc135889594bb371c082d20fb7ee7303b174874c996888cc8511/uwsgi-2.0.15.tar.gz (795kB)
Collecting vine==1.1.4 (from -r requirements.txt (line 21))
Downloading https://files.pythonhosted.org/packages/10/50/5b1ebe42843c19f35edb15022ecae339fbec6db5b241a7a13c924dabf2a3/vine-1.1.4-py2.py3-none-any.whl
Collecting psycopg2-binary==2.7.4 (from -r requirements.txt (line 22))
Downloading https://files.pythonhosted.org/packages/77/09/4991fcd9a8f4bea1ee3948e1729fa17c184d25bd10809bacc143626361b9/psycopg2-binary-2.7.4.tar.gz (426kB)
Collecting ptvsd==3.2.1 (from -r requirements.txt (line 23))
Downloading https://files.pythonhosted.org/packages/37/44/6dedb2ef160c72c46c4575885bb9d2d6c464202915c14312d02fad0b9c70/ptvsd-3.2.1-py2.py3-none-any.whl (59kB)
Installing collected packages: vine, amqp, billiard, pytz, kombu, celery, Django, django-cors-headers, pika, six, django-notifs, django-templated-mail, djangorestframework, PyJWT, djangorestframework-jwt, djoser, greenlet, gevent, simplejson, uwsgi, psycopg2-binary, ptvsd
Running setup.py install for django-notifs: started
Running setup.py install for django-notifs: finished with status 'done'
Running setup.py install for greenlet: started
Running setup.py install for greenlet: finished with status 'error'
Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g5y1o81k/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-mz7pfy5s/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'greenlet' extension
creating build
creating build/temp.linux-x86_64-3.7
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.7m -c greenlet.c -o build/temp.linux-x86_64-3.7/greenlet.o
greenlet.c: In function ‘g_switchstack’:
greenlet.c:463:29: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_type’; did you mean ‘curexc_type’?
current->exc_type = tstate->exc_type;
^~
greenlet.c:464:30: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_value’; did you mean ‘curexc_value’?
current->exc_value = tstate->exc_value;
^~
greenlet.c:465:34: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
current->exc_traceback = tstate->exc_traceback;
^~
greenlet.c:485:9: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_type’; did you mean ‘curexc_type’?
tstate->exc_type = target->exc_type;
^~
greenlet.c:487:9: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_value’; did you mean ‘curexc_value’?
tstate->exc_value = target->exc_value;
^~
greenlet.c:489:9: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
tstate->exc_traceback = target->exc_traceback;
^~
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g5y1o81k/greenlet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-mz7pfy5s/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-g5y1o81k/greenlet/
The command '/bin/sh -c python -m pip install -r requirements.txt --no-cache-dir' returned a non-zero code: 1
Although the solution of ClumsyPuffin works well it uses a heavier distribution.
I just fixed this issue by adding the following line in the Dockerfile before installing the requirements.
RUN apk add build-base
build-base is a meta-package that will install the GCC, libc-dev and
binutils packages (amongst others).
https://wiki.alpinelinux.org/wiki/GCC
This is due to a cython incompatability issue with python 3.7 (https://github.com/cython/cython/issues/1978).
Modify your image name as FROM python:3.6-stretch and this should work fine

this page is not working - Docker

I have a local docker image running with a django project that i am running. The docker image is up but when i go to the local host with port 8000 which is set, gives a message that the page is not working and that 127.0.0.1 didn’t send any data.
Here is the docker code:
omars-mbp:Split omarjandali$ docker build -t split .
Sending build context to Docker daemon 222.2kB
Step 1/7 : FROM python:3
---> 79e1dc9af1c1
Step 2/7 : WORKDIR user
---> 15e014da5b80
Removing intermediate container f4081817276f
Step 3/7 : COPY requirements.txt ./
---> 1f444390862b
Step 4/7 : EXPOSE 8000
---> Running in f75a6674ade2
---> 7641865ffc85
Removing intermediate container f75a6674ade2
Step 5/7 : RUN pip install -r requirements.txt
---> Running in 40738a20f481
Collecting Django==1.11.5 (from -r requirements.txt (line 1))
Downloading Django-1.11.5-py2.py3-none-any.whl (6.9MB)
Collecting gunicorn==19.6.0 (from -r requirements.txt (line 2))
Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
Collecting pytz (from Django==1.11.5->-r requirements.txt (line 1))
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
Installing collected packages: pytz, Django, gunicorn
Successfully installed Django-1.11.5 gunicorn-19.6.0 pytz-2017.3
---> 371a95617f78
Removing intermediate container 40738a20f481
Step 6/7 : COPY . .
---> fa31f9520063
Step 7/7 : CMD python manage.py runserver 0.0.0.0:8000
---> Running in 28b6a097dac4
---> c0d19bca8c2d
Removing intermediate container 28b6a097dac4
Successfully built c0d19bca8c2d
Successfully tagged split:latest
omars-mbp:Split omarjandali$ docker run -d -p 8000:8000 split
d70035b14ab0c2046f2bfc8418960a0b1e5dd8bb75e09a045b41e94bcb097aa4
omars-mbp:Split omarjandali$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d70035b14ab0 split "python manage.py ..." 4 seconds ago Up 2 seconds 0.0.0.0:8000->8000/tcp focused_shirley
docker file:
FROM python:3
WORKDIR user
COPY requirements.txt ./
EXPOSE 8000
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

docker image is running but webpage error - Docker

I have a basic django project and I am trying to get it running locally through docker. I have the docker file. I build the docker image. I ran the docker image. It is running, but my webpage shows an error on the screen like it is not connecting to the docker server... Here is what I have:
docker file:
FROM python:3
WORKDIR general
COPY requirements.txt ./
EXPOSE 8000
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Here is how I am buiding and running this project:
omars-mbp:split omarjandali$ docker build -t splitbeta/testing2 .
Sending build context to Docker daemon 223.7kB
Step 1/7 : FROM python:3
---> 79e1dc9af1c1
Step 2/7 : WORKDIR general
---> 04a6f8a7f92a
Removing intermediate container b2ffb485e485
Step 3/7 : COPY requirements.txt ./
---> 649d77ec499e
Step 4/7 : EXPOSE 8000
---> Running in 7d8d6fe8de1d
---> c328d885a5f1
Removing intermediate container 7d8d6fe8de1d
Step 5/7 : RUN pip install -r requirements.txt
---> Running in 1c9aca43dc14
Collecting Django==1.11.5 (from -r requirements.txt (line 1))
Downloading Django-1.11.5-py2.py3-none-any.whl (6.9MB)
Collecting gunicorn==19.6.0 (from -r requirements.txt (line 2))
Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
Collecting pytz (from Django==1.11.5->-r requirements.txt (line 1))
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
Installing collected packages: pytz, Django, gunicorn
Successfully installed Django-1.11.5 gunicorn-19.6.0 pytz-2017.3
---> 602e88557c8b
Removing intermediate container 1c9aca43dc14
Step 6/7 : COPY . .
---> 55cff629cb51
Step 7/7 : CMD python manage.py runserver 0.0.0.0:8000
---> Running in efd75f8fb602
---> 2cef664a626d
Removing intermediate container efd75f8fb602
Successfully built 2cef664a626d
Successfully tagged splitbeta/testing2:latest
omars-mbp:split omarjandali$ docker run -d spltibeta/testing2
Here is the project running:
omars-mbp:split omarjandali$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fc14f03a18b0 splitbeta/testing2 "python manage.py ..." 3 seconds ago Up 3 seconds 8000/tcp loving_volhard
THe webpage is giving the following error when it is supposed to display a template page....
This site can’t be reached
127.0.0.1 refused to connect.
I got it running yesterday but it is not working any more... I dont know why. I didnt change anything
I am logged into my dockerhub account in my terminal
It seems your Docker run command doesn't publish port 8000. By default, docker won't publish any container ports on the host system if you don't tell it to explicitly. Try using the -p or --publish option of docker run:
docker run -d -p 8000:8000 spltibeta/testing2
Alternatively, you can use the -P or --publish-all option to publish all exposed ports of your container on your host system. This will assign a random port on the host.
docker run -d -P spltibeta/testing2

Configuring Django with Nginx, uWSGI and Postgres on Docker

I'm trying to setup a Django app on Docker with Nginx, uWSGI and Postgres. I found this great guide on setting up Compose for Django and Postgres: https://docs.docker.com/v1.5/compose/django/
However, now I need to add Nginx and uWSGI. I've tried using files of this repo (https://github.com/baxeico/django-uwsgi-nginx) with the Compose setup of the Docker docs but without succes, sadly.
This is what happens when I enter docker-compose run web:
Step 17 : RUN pip install -r /home/docker/code/app/requirements.txt
---> Running in e1ec89e80d9c
Collecting Django==1.9.1 (from -r /home/docker/code/app/requirements.txt (line 1))
/usr/local/lib/python2.7/dist-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading Django-1.9.1-py2.py3-none-any.whl (6.6MB)
Collecting psycopg2 (from -r /home/docker/code/app/requirements.txt (line 2))
Downloading psycopg2-2.6.1.tar.gz (371kB)
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-XRgbSA/psycopg2
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r /home/docker/code/app/requirements.txt' returned a non-zero code: 1
This is my Dockerfile:
from ubuntu:precise
run echo "deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted" | tee -a /etc/apt/sources.list.d/precise-updates.list
# update packages
run apt-get update
# install required packages
run apt-get install -y python python-dev python-setuptools python-software-properties
run apt-get install -y sqlite3
run apt-get install -y supervisor
# add nginx stable ppa
run add-apt-repository -y ppa:nginx/stable
# update packages after adding nginx repository
run apt-get update
# install latest stable nginx
run apt-get install -y nginx
# install pip
run easy_install pip
# install uwsgi now because it takes a little while
run pip install uwsgi
# install our code
add . /home/docker/code/
# setup all the configfiles
run echo "daemon off;" >> /etc/nginx/nginx.conf
run rm /etc/nginx/sites-enabled/default
run ln -s /home/docker/code/nginx-app.conf /etc/nginx/sites-enabled/
run ln -s /home/docker/code/supervisor-app.conf /etc/supervisor/conf.d/
# run pip install
run pip install -r /home/docker/code/app/requirements.txt
run cd /home/docker/code/app && ./manage.py syncdb --noinput
expose 80
cmd ["supervisord", "-n"]
And the docker-compose.yml:
db:
image: postgres
web:
build: .
command: python vms/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
links:
- db
There are also files named nginx-app.conf, supervisor-app.conf, uwsgi_params and uwsgi.ini. These are all from the aforementioned repo. Requirements.txt contains Django 1.9.1, psycopg2 and requests.
If there is a better alternative to this Frankenstein project, I'd love to hear it.
On Ubuntu, make sure that python-dev and libpq-dev have been installed using apt-get, before trying to install psycopg2 using pip.
See the installation docs for more info.