I got an error when deploy Django application to IBM Bluemix. When i see log it's show this.
2015-09-09T22:08:00.05+0700 [STG/0] ERR You are using pip version 6.1.0
.dev0, however version 7.1.2 is available.
2015-09-09T22:08:00.05+0700 [STG/0] ERR You should consider upgrading via t
he 'pip install --upgrade pip' command.
2015-09-09T22:08:00.28+0700 [STG/0] OUT -----> Preparing static assets
2015-09-09T22:08:01.02+0700 [STG/0] OUT Running collectstatic...
2015-09-09T22:08:01.84+0700 [STG/0] OUT 175 static files copied to '
/app/static'.
2015-09-09T22:08:17.95+0700 [STG/166] OUT -----> Uploading droplet (46M)
2015-09-09T22:08:34.18+0700 [DEA/166] OUT Starting app instance (index 0) wit
h guid a416b8bf-5d53-47d5-9d99-d39c4730cd22
2015-09-09T22:09:03.53+0700 [API/4] OUT App instance exited with guid a416b
8bf-5d53-47d5-9d99-d39c4730cd22 payload: {"cc_partition"=>"default", "droplet"=>
"a416b8bf-5d53-47d5-9d99-d39c4730cd22", "version"=>"31f9acf2-6bf7-4709-83fd-2ce0
00fa4483", "instance"=>"f4fc8d2f0e4f4bdeb4260fa8cae1f68f", "index"=>0, "reason"=
>"CRASHED", "exit_status"=>2, "exit_description"=>"app instance exited", "crash_
timestamp"=>1441811343}
For deploy appliction i have 3 files, that is requirements.txt, manifest.yml and run.sh file.
in my manifest.yml file
applications:
- name: RoyalCaninExam
memory: 256M
# This is command provided by cf -c option
command: bash ./run.sh
buildpack: python_buildpack
path: .
services:
- mysql-royalcanin
and in run.sh file
if [ -z "$VCAP_APP_PORT" ];
then SERVER_PORT=5000;
else SERVER_PORT="$VCAP_APP_PORT";
fi
echo [$0] port is------------------- $SERVER_PORT
python manage.py syncdb --noinput
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin#admin.com', 'admin')" | python manage.py shell
echo [$0] Starting Django Server...
python manage.py runserver 0.0.0.0:$SERVER_PORT --noreload
It looks like your run.sh script is not running as there is no output in your log. Please make sure that your run.sh does not contain any Windows EOL encoding as this causes problems with the Python buildpack. Change any EOL encoding in that file to UNIX using a file editor of your choice.
Related
So I am pretty new to docker and django. Unfortunately while running the below command on my linux machine which i am connected using my physical windows machine using putty:
docker-compose build
I am getting an error:
Error processing tar file(exit status 1): open /myenv/include/python3.6m/Python-ast.h: no such file or directory
'myenv' is the environment I have created inside my folder.
I am getting a container started on port 9000. The app doesn't have anything yet just a simple project so i just expect to see the 'congratulations' screen. I don't know where I am going wrong. My final goal would be to run the docker url in my windows browser and see the screen of docker container.
This is my docker-compose.yml file:
version: '3'
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:9000
ports:
- 202.179.92.106:8000:9000
the IP: 202.179.92.106 is my public IP. I did the above binding so as to access the docker container from my windows machine. Would request additional inputs for the port binding as well if correct/incorrect.
Below is my Dockerfile:
FROM python:3.6.9
RUN mkdir djangotest
WORKDIR djangotest
ADD . /djangotest
RUN pip install -r requirements.txt
Please help me out peeps!
If you have a virtual environment in your normal development tree, you can't copy it into a Docker image. You can exclude this from the build sequence by mentioning it in a .dockerignore file:
# .dockerignore
myenv
Within the Dockerfile, the RUN pip install line will install your application's dependencies into the Docker image, so you should have a complete self-contained image.
I am trying to host my Django application on Cloud Foundry, After installing the packages mentioned in requirement.txt file, I m getting error saying the package is installed in path "/tmp/somedir/deps/0/python/bin" which is not on Path. So I want to know how can I add this directory to the Path.
I am using CF CLI's CF push manifest.yml cmd to push the django application.
Adding the manifest file:
Manifest.yml:
applications:
- name: myapp
domain: domain_name
memory: 1024M
disk_quota: 1024M
buildpack: python_buildpack
command: bash ./run.sh
env:
DISABLE_COLLECTSTATIC : 1
Adding run.sh file:
#!/bin/bash
if [ -z “$VCAP_APP_PORT” ];
then SERVER_PORT=XX;
else SERVER_PORT=”$VCAP_APP_PORT”;
fi
echo port is $SERVER_PORT
echo [$0] Starting Django Server…
python manage.py runserver 0.0.0.0:$SERVER_PORT — noreload
I think this is simply a bug in the Python Buildpack, that will be solved when https://github.com/cloudfoundry/python-buildpack/pull/601 is merged.
I had a working Django project that had built and deployed many images over the last few weeks. My django project kept working fine when ran as "python manage.py runserver" and the Docker images kept being built fine (all successful builds). However the django app now doesn't deploy. What could be the issue and where should I start to look for it? I've tried the logs but they only say "Starting Django" without actually starting the service
I use github and have gone back to previous versions of the code and none of them now work, even though the code is exactly the same. It also fails to deploy the Django server on AWS Elastic Beanstalk infrastructure which is my ultimate goal with this code.
start.sh:
#!/bin/bash
echo Starting Django
cd TN_API
exec python ../manage.py runserver 0.0.0.0:8000
Dockerfile:
FROM python:2.7.13-slim
# Set the working directory to /app
WORKDIR /TN_API
# Copy the current directory contents into the container at /app
ADD . /TN_API
# COPY startup script into known file location in container
COPY start.sh /start.sh
# Install requirements
RUN pip install -r requirements.txt
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
Commands:
sudo docker run -d tn-api
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d28115a919f9 tn-api "/start.sh" 11 seconds ago Up 8 seconds 8000/tcp festive_darwin
sudo docker logs [container id]
Starting Django
(doesn't do the whole:
Performing system checks...
System check identified no issues (0 silenced).
August 06, 2017 - 20:54:36
Django version 1.10.5, using settings 'TN_API.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.)
I changed several things and although it doesn't work locally it seems to work fine when deployed to AWS. I still don't get the feedback I used to get such as below but that's ok. I can hit the server and it works. Thank you all for your help.
Performing system checks...
System check identified no issues (0 silenced). August 06, 2017 - 20:54:36 Django version 1.10.5, using settings 'TN_API.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
It looks like the path is wrong for the manage.py script in /start.sh.
Your start.sh:
#!/bin/bash
echo Starting Django
cd TN_API
exec python ../manage.py runserver 0.0.0.0:8000
Seeing that you set WORKDIR to you project directory in the Dockerfile, the start.sh script is actually run from inside the project directory - which means it is actually doing this:
cd /TN_API # WORKDIR directive in Dockerfile
echo Starting Django # from the start.sh script
cd /TN_API/TN_API # looking for TN_API within your current pwd
exec python /TN_API/manage.py runserver 0.0.0.0:8000 # goes up a level (..) to look for manage.py
So it could be that your context for running runserver is off.
You can avoid this path jumping by rewriting your Dockerfile to include an CMD directive as follows:
FROM python:2.7.13-slim
# Set the working directory to /app
WORKDIR /TN_API
# Copy the current directory contents into the container at /app
ADD . /TN_API
# Install requirements
RUN pip install -r requirements.txt
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
# CMD specifcies the command to execute to start the server running.
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Here using python manage.py runserver 0.0.0.0:8000 will work since you set the WORKDIR to your project directory already. So you wouldn't need your start.sh script necessarily.
I am using jenkins for continuous integration from gitlab and continuous deployment. My "execute shell" consist of the following commands .
#!/bin/bash
source /my_env/bin/activate # Activate the virtualenv
cd /var/lib/jenkins/workspace/Operations_central
#pip install -r requirements.txt # Install or upgrade dependencies
python manage.py makemigrations
python manage.py migrate # Apply South's database
sudo service nginx restart
fuser -n tcp -k 8088
gunicorn applicationfile.wsgi:application --bind=myserverip:portno`
I followed the instructions for setting up the official Django docker image, found here. First, I created a scaffold for my project, by running
$ docker run -it --rm --user "$(id -u):$(id -g)" -v "$PWD":/usr/src/app -w /usr/src/app django django-admin.py startproject mysite2
Then, I followed the instructions for creating the Dockerfile, and after building the image, I ran the docker image with
docker run --name some-django-app -p 8000:8000 -d my-django-app
And it worked!
So just like the default page suggested, I decided to create my first app with
docker exec <docker container ID> bash -c "python /folder/to/mysite2/manage.py startapp polls"
But then I received the error message
Traceback (most recent call last):
File "/folder/to/mysite2/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
After some Googling, this indicates django isn't installed. But I'm confused; I thought this docker image was supposed to be shipped with django. I know django was used once before since the start page came up.
I thought the point of the docker image was so I didn't have to install django on the main system. How is docker exec supposed to be used in this scenario?
Vagrantfile
config.vm.provision "docker" do |d|
d.pull_images "django"
end
Dockerfile
FROM django:onbuild
Your working directory probably isn't /folder/to/mysite/ so django can't find the settings file to import.
In your dockerfile, set WORKDIR=/folder/to/mysite/, then simplify your run command to:
docker exec -t <docker container ID> bash -c "python ./manage.py startapp polls"