0
votes

I'm looking to deploy a simple application which uses Django and celery.

docker-compose.yml:

version: "3.8"
   
services:
    django:
        build: .
        container_name: django
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - .:/usr/src/app/
        ports:
            - "8000:8000"
        environment:
            - DEBUG=1
            - CELERY_BROKER=redis://redis:6379/0
            - CELERY_BACKEND=djcelery.backends.database:DatabaseBackend
        depends_on:
            - redis
    celery:
        build: .
        command: celery -A core worker -l INFO
        volumes:
            - .:/usr/src/app
        environment:
            - DEBUG=1
            - CELERY_BROKER=redis://redis:6379/0
            - CELERY_BACKEND=djcelery.backends.database:DatabaseBackend
        depends_on:
            - django
            - redis
    redis:
        image: "redis:alpine"
        
volumes:
    pgdata:


Dockerfile:

FROM python:3.7
WORKDIR /app
ADD . /app

#Install dependencies for PyODBC
RUN apt-get update \
 && apt-get install unixodbc -y \
 && apt-get install unixodbc-dev -y \
 && apt-get install tdsodbc -y \
 && apt-get clean -y


# install ODBC driver in docker image
RUN apt-get update \
 && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
 && curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list \
 && apt-get update \
 && ACCEPT_EULA=Y apt-get install --yes --no-install-recommends msodbcsql17 \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* \
 && rm -rf /tmp/*


# install requirements
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 5000

ENV NAME OpentoAll

CMD ["python", "app.py"]

Project Directories: enter image description here

When I run "docker-compose up" locally, the celery worker is run and I am able to go to localhost:8000 to access the API to make asynchronous requests to a celery task.

Now I'm wondering how can I deploy this to the cloud environment? What would be the image I would need to build and deploy? Thanks

1
When you say "cloud environment", do you have a specific setup in mind? You already have a Dockerfile that builds an image, so you would need to arrange to push it to a registry of some sort (Docker Hub, something your cloud provider hosts like ECR/ACR/GCR, ...). I'd recommend deleting the volumes: that overwrite the content in the image and testing this setup locally before trying to deploy to somewhere more involved. - David Maze

1 Answers

0
votes

You will need to install an application server (eg. gunicorn) in your django container and then run in on say port 8000. You'll also need a webserver (eg. nginx) in a container or installed on the host. The web server will need to act as a reverse proxy for gunicorn and also serve your static Django content.