Giter Club home page Giter Club logo

ruddra / docker-django Goto Github PK

View Code? Open in Web Editor NEW
472.0 20.0 129.0 70 KB

A complete docker package for django which is easy to understand and can be deployed anywhere(supports Data Science related libraries like numpy, scipy etc).

Home Page: https://ruddra.com/docker-django-nginx-postgres/

License: MIT License

Makefile 3.03% Python 52.25% HTML 8.17% Dockerfile 12.62% Shell 23.92%
django docker python nginx postgres container redis boilerplate celery numpy

docker-django's Introduction

Deploy Django using Nginx, Celery, Redis and Postgresql with Docker

A boilerplate to deploy Django with cool stuff. Also serves as an example project from these tutorial:

  1. Deploy Django, Gunicorn, NGINX, Postgresql using Docker
  2. Serve Static Files by Nginx from Django using Docker
  3. Docker: Use Celery in Django(Redis as Broker)

Where it is described how this boilerplate was created from scratch so that you can build your own.

Advantages

  1. Ready to use with your django project.
  2. Combined with NGINX, Redis, Celery to handle relevent things.
  3. Alpine based images are used, so that sizes of the images are compartively low.
  4. Now comes built it with Numpy, Scipy and Pandas support. So you can integrate your datascience projects with this. Instructions for integrating these libraries are also shared in the Dockerfile.
  5. With Numpy, Pandas and Scipy dependecies installed, the total size is 657MB(may differ if you have more packages). Without these, size reduces to 390MB.
  6. Now comes with support to install Pillow using django.

Now Featuring Numpy, Scipy and Pandas

In the Dockerfile, there are detailed instructions on how to install data science dependencies.

PS: Here is a gist which is more useful for Numpy, Pandas, Scipy etc. And it is usable with this project's docker-compose.yml file. Just you need to replace the Dockerfile from ./compose directory with the one in the gist.

Basic Usage

  1. First run make build inside root directory.
  2. Then run make up to start up the project for first time.
  3. Use/update environment variables from .envs folder.

Checkout the commands section for more usage.

Preview

A default Django project resides in src directory. So, when you start the project, you will see the following screen in 8000 port:

Demo One

Also when you access the django container log via make log-web, you will see the following:

Demo Two

Commands

To use this project, run this commands:

  1. make up to build the project and starting containers.
  2. make build to build the project.
  3. make start to start containers if project has been up already.
  4. make stop to stop containers.
  5. make shell-web to shell access web container.
  6. make shell-db to shell access db container.
  7. make shell-nginx to shell access nginx container.
  8. make logs-web to log access web container.
  9. make logs-db to log access db container.
  10. make logs-nginx to log access nginx container.
  11. make collectstatic to put static files in static directory.
  12. make log-web to log access web container.
  13. make log-db to log access db container.
  14. make log-nginx to log access nginx container.
  15. make restart to restart containers.

License

MIT.

Contribute

Feel free to fork and create PR.

docker-django's People

Contributors

ruddra avatar serkansokmen avatar zachary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-django's Issues

abc.com:8000 works, but abc:80 doesn't

Hello!

I'm trying to add domain abc.com.
My conf looks like this:

upstream web {  
  ip_hash;
  server web:8000;
}

server {

    location /static/ {    
        autoindex on;    
        alias /src/static/; 
    }

    location / {
        proxy_pass http://web/;
    }
    listen 8000;
    server_name abc.com;
}

and it works.

However if I replace listen 8000 to listen 80 -- it doesn't. What am I doing wrong ?

fix db name schema

please change the variable name in docker-django.envs.django
from DATABASE=django_db to DB_NAME=django_db

The Django is creating in schema postgress, not in django_db

another hint... to enable external access to the container db just include these 2 variables
PGHOST=localhost
PGPORT=5444

Add celery 4.2.0

With celery 4.0.0, i had non stable work...

/usr/local/lib/python3.5/site-packages/celery/platforms.py:792: RuntimeWarning: You're running the worker with superuser privileges: this is
dz01 | absolutely not recommended!
dz01 |
dz01 | Please specify a different user using the -u option.
dz01 |
dz01 | User information: uid=0 euid=0 gid=0 egid=0
dz01 |
dz01 | uid=uid, euid=euid, gid=gid, egid=egid,
dz01 | Traceback (most recent call last):
dz01 | File "/usr/local/lib/python3.5/site-packages/kombu/transport/base.py", line 123, in getattr
dz01 | return self[key]
dz01 | KeyError: 'async'
dz01 |
dz01 | During handling of the above exception, another exception occurred:
dz01 |
dz01 | Traceback (most recent call last):
dz01 | File "/usr/local/bin/celery", line 11, in
dz01 | sys.exit(main())
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/main.py", line 14, in main
dz01 | _main()
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/celery.py", line 326, in main
dz01 | cmd.execute_from_commandline(argv)
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/celery.py", line 488, in execute_from_commandline
dz01 | super(CeleryCommand, self).execute_from_commandline(argv)))
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/base.py", line 278, in execute_from_commandline
dz01 | return self.handle_argv(self.prog_name, argv[1:])
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/celery.py", line 480, in handle_argv
dz01 | return self.execute(command, argv)
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/celery.py", line 412, in execute
dz01 | ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/worker.py", line 221, in run_from_argv
dz01 | return self(*args, **options)
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/base.py", line 241, in call
dz01 | ret = self.run(*args, **kwargs)
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/bin/worker.py", line 255, in run
dz01 | **kwargs)
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/worker/worker.py", line 99, in init
dz01 | self.setup_instance(**self.prepare_args(**kwargs))
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/worker/worker.py", line 122, in setup_instance
dz01 | self.should_use_eventloop() if use_eventloop is None
dz01 | File "/usr/local/lib/python3.5/site-packages/celery/worker/worker.py", line 241, in should_use_eventloop
dz01 | self._conninfo.transport.implements.async and
dz01 | File "/usr/local/lib/python3.5/site-packages/kombu/transport/base.py", line 125, in getattr
dz01 | raise AttributeError(key)
dz01 | AttributeError: async
dz01 exited with code 1

Trying localhost on browser not working

With a clean pull of this repo, when I start the containers and I try to access to the django app via browser it doesn't work.
If I try localhost:80 it results in a ERR_CONNECTION_REFUSED, no server in this adress
If I try localhost:8000 it results in a ERR_EMPTY_RESPONSE.
Any idea how to solve it?

PS: I'm using Docker on Mac
The lastest log in the web container is:

dsz01     | [2017-06-13 12:04:51 +0000] [9] [INFO] Starting gunicorn 19.6.0
dsz01     | [2017-06-13 12:04:51 +0000] [9] [INFO] Listening at: http://127.0.0.1:8000 (9)
dsz01     | [2017-06-13 12:04:51 +0000] [9] [INFO] Using worker: sync
dsz01     | [2017-06-13 12:04:51 +0000] [12] [INFO] Booting worker with pid: 12

docker-compose up exit with code 1

My fresh installation not working at all.

Whenever I do

docker-compose up

get following error & exit. If I check in the browser I get ngnix Bad Gateway error.

dz01     | Operations to perform:
dz01     |   Apply all migrations: admin, auth, contenttypes, sessions
dz01     | Running migrations:
dz01     |   Applying contenttypes.0001_initial... OK
dz01     |   Applying auth.0001_initial... OK
dz01     |   Applying admin.0001_initial... OK
dz01     |   Applying admin.0002_logentry_remove_auto_add... OK
dz01     |   Applying contenttypes.0002_remove_content_type_name... OK
dz01     |   Applying auth.0002_alter_permission_name_max_length... OK
dz01     |   Applying auth.0003_alter_user_email_max_length... OK
dz01     |   Applying auth.0004_alter_user_username_opts... OK
dz01     |   Applying auth.0005_alter_user_last_login_null... OK
dz01     |   Applying auth.0006_require_contenttypes_0002... OK
dz01     |   Applying auth.0007_alter_validators_add_error_messages... OK
dz01     |   Applying auth.0008_alter_user_username_max_length... OK
dz01     |   Applying sessions.0001_initial... OK
dz01     | [2018-08-09 11:25:17 +0000] [10] [INFO] Starting gunicorn 19.6.0
dz01     | [2018-08-09 11:25:17 +0000] [10] [INFO] Listening at: http://0.0.0.0:8000 (10)
dz01     | [2018-08-09 11:25:17 +0000] [10] [INFO] Using worker: sync
dz01     | [2018-08-09 11:25:17 +0000] [16] [INFO] Booting worker with pid: 16
dz01     | No Local Settings Found
dz01     | No Local Settings Found
dz01     | /usr/local/lib/python3.7/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>.
dz01     |   """)
dz01     | /usr/local/lib/python3.7/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>.
dz01     |   """)
dz01     | /usr/local/lib/python3.7/site-packages/celery/platforms.py:796: RuntimeWarning: You're running the worker with superuser privileges: this is
dz01     | absolutely not recommended!
dz01     | 
dz01     | Please specify a different user using the --uid option.
dz01     | 
dz01     | User information: uid=0 euid=0 gid=0 egid=0
dz01     | 
dz01     |   uid=uid, euid=euid, gid=gid, egid=egid,
dz01     | [2018-08-09 11:25:18,476: CRITICAL/MainProcess] Unrecoverable error: SyntaxError('invalid syntax', ('/usr/local/lib/python3.7/site-packages/celery/backends/redis.py', 22, 19, 'from . import async, base\n'))
dz01     | Traceback (most recent call last):
dz01     |   File "/usr/local/lib/python3.7/site-packages/kombu/utils/objects.py", line 42, in __get__
dz01     |     return obj.__dict__[self.__name__]
dz01     | KeyError: 'backend'
dz01     | 
dz01     | During handling of the above exception, another exception occurred:
dz01     | 
dz01     | Traceback (most recent call last):
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/worker/worker.py", line 205, in start
dz01     |     self.blueprint.start(self)
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/bootsteps.py", line 115, in start
dz01     |     self.on_start()
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/apps/worker.py", line 139, in on_start
dz01     |     self.emit_banner()
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/apps/worker.py", line 154, in emit_banner
dz01     |     ' \n', self.startup_info(artlines=not use_image))),
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/apps/worker.py", line 217, in startup_info
dz01     |     results=self.app.backend.as_uri(),
dz01     |   File "/usr/local/lib/python3.7/site-packages/kombu/utils/objects.py", line 44, in __get__
dz01     |     value = obj.__dict__[self.__name__] = self.__get(obj)
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/app/base.py", line 1196, in backend
dz01     |     return self._get_backend()
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/app/base.py", line 914, in _get_backend
dz01     |     self.loader)
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/app/backends.py", line 70, in by_url
dz01     |     return by_name(backend, loader), url
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/app/backends.py", line 50, in by_name
dz01     |     cls = symbol_by_name(backend, aliases)
dz01     |   File "/usr/local/lib/python3.7/site-packages/kombu/utils/imports.py", line 56, in symbol_by_name
dz01     |     module = imp(module_name, package=package, **kwargs)
dz01     |   File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
dz01     |     return _bootstrap._gcd_import(name[level:], package, level)
dz01     |   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
dz01     |   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
dz01     |   File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
dz01     |   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
dz01     |   File "<frozen importlib._bootstrap_external>", line 724, in exec_module
dz01     |   File "<frozen importlib._bootstrap_external>", line 860, in get_code
dz01     |   File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
dz01     |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
dz01     |   File "/usr/local/lib/python3.7/site-packages/celery/backends/redis.py", line 22
dz01     |     from . import async, base
dz01     |                       ^
dz01     | SyntaxError: invalid syntax
dz01 exited with code 1

Assistance with the configuring the DB to access psql command

if I try to use make shell-db and then do psql it will tell me that psql: FATAL: role "root" does not exist

How can I configure it so that I can access psql in some way. This is has been my biggest issue with dockerizing django+postgrest and this info might be useful to others as well if you could help me with it.

Celery, no module named 'utility'

At ligne 41 of the docker-compose.yml there is this line :

command: celery worker --app=utility.tasks

I get this error when I'm trying to run docker-compose up :

ModuleNotFoundError: No module named 'utility'

Is there any way to resolve it ?

Update redis-py

Redis transport requires redis-py versions 3.2.0 or later. You have 2.10.6

Upgrade to Python 3.7

We will upgrade the python version to Python 3.7 as soon as Celery 4.3 is released

How to change user, password and database of the bank after it has already been created previously?

hello,
I'm enjoying testing this project. It's a nice job. However I have a doubt:
I ran make build. Only after that I changed the variables present in the .django and .postgres files (user, database and password).
I did the build again but I noticed that the database is still created with the previous values of user, database and password. I noticed in the log that the bank was restored.

How do I change postgres username, database and password?

Issue with celery naming conventions

currently in the celery release there is an issue with naming an import async which is a reserved keyword. This can be resolved by adding the following to the dockerfile
RUN pip install --upgrade https://github.com/celery/celery/tarball/master
for reference here is the issue on celery and a release is planned to fix the issue but in the meantime if anyone is looking for it here

Python Pandas

Hi, thank you for this Dockerimage.
I have problems with Pandas and Numpy

its my requirements.pip
amqp==2.4.2
billiard==3.6.0.0
celery==4.3.0
Django==2.2.1
gunicorn==19.9.0
kombu==4.5.0
pytz==2019.1
redis==3.2.1
sqlparse==0.3.0
vine==1.3.0
pandas==0.25.1

ERROR:
.... in build_sources File "/tmp/easy_install-lcv5khez/numpy-1.17.3/numpy/distutils/command/build_src.py", line 286, in build_library_sources File "/tmp/easy_install-lcv5khez/numpy-1.17.3/numpy/distutils/command/build_src.py", line 369, in generate_sources File "numpy/core/setup.py", line 669, in get_mathlib_info "depends": tseries_depends, RuntimeError: Broken toolchain: cannot link a simple C program ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.pip' returned a non-zero code: 1
in next step i try it with apt packages:
Dockerfile
`FROM python:3.8.0-alpine3.10
ENV PYTHONUNBUFFERED 1
ENV C_FORCE_ROOT true
RUN mkdir /src
RUN mkdir /static
WORKDIR /src

install psycopg2

RUN apk update
&& apk add --virtual build-deps gcc python3-dev musl-dev
&& apk add postgresql-dev
&& pip install psycopg2
&& pip install numpy \ . ###NEW LINE
&& pip install pandas \ ### NEW LINE
&& apk del build-deps

ADD ./src /src
RUN pip install --upgrade pip
RUN pip install -r requirements.pip
CMD python manage.py collectstatic --no-input;python manage.py migrate; gunicorn mydjango.wsgi -b 0.0.0.0:8000 & celery worker --app=myapp.tasks
`

ERROR:
`
File "/tmp/pip-install-74d91rss/pandas/setup.py", line 409, in build_extensions
self.check_cython_extensions(self.extensions)
File "/tmp/pip-install-74d91rss/pandas/setup.py", line 399, in check_cython_extensions
raise Exception(
Exception: Cython-generated file 'pandas/_libs/algos.c' not found.
Cython is required to compile pandas from a development branch.
Please install Cython or download a release package of pandas.

----------------------------------------

ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-74d91rss/pandas/setup.py'"'"'; file='"'"'/tmp/pip-install-74d91rss/pandas/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-1mjw0bgj/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
`
i hope, you can help me

'make' is not recognized

I have error:

D:\docker-django>make shell-web
'make' is not recognized as an internal or external command,
operable program or batch file.

Should it be run from root folder?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.