Deploying project in Docker with Angular 4, Django and postgresql

I am trying to deploy on Heroku my project in Docker with Angular 4 frontend with Django backend and postgresql database. At this moment my files look as shown below. I am note sure if this is done properly? I pushed it using heroku container:push web --app myproject but it doesn’t work (Logs). I assume that if I use Docker I don’t have to create Procfile etc.? May the error be caused by lack of migration of database?

I have no idea that I’m moving into the right direction but I’m trying to migrate my database. Maybe my error is caused by lack of db?

  • How to pass parameters from docker to angular js?
  • Confusion on using docker-compose volumes to serve django static files
  • Wrong order of running docker containers in convox/docker-compose
  • You're accessing the development server over HTTPS, but it only supports HTTP when using Docker
  • Linking django and mysql containers using docker-compose
  • Can't curl linked container in Docker even though I can ping it
  • When I run heroku run python manage.py migrate, I get:

    django.db.utils.OperationalError: could not translate host name “db”
    to address: Name or service not known

    Logs:

    2017-07-07T10:27:30.448951+00:00 heroku[web.1]: State changed from crashed to starting
    2017-07-07T10:27:30.436282+00:00 heroku[web.1]: Process exited with status 0
    2017-07-07T10:27:50.846928+00:00 heroku[web.1]: Starting process with command `python3`
    2017-07-07T10:27:53.350381+00:00 heroku[web.1]: Process exited with status 0
    2017-07-07T10:27:53.365013+00:00 heroku[web.1]: State changed from starting to crashed
    2017-07-07T10:27:53.876208+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=e1f8edfc-7dc4-4bd3-91be-0a853e948452 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https
    2017-07-07T10:28:43.444860+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=361846d1-41cd-403a-989f-4c29a0d1179e fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https
    2017-07-07T10:28:43.984059+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host= myproject.herokuapp.com request_id=658795c8-0ba7-4988-9d39-34601b1334c7 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https
    2017-07-07T10:28:44.673789+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=63fbabdc-7ba7-4997-81be-c601a0d83368 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https
    2017-07-07T10:29:53.091547+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=a3943544-9dc4-44f0-b788-a462cdfba7d0 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https
    2017-07-07T10:29:54.419623+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host= myproject.herokuapp.com request_id=eb5191e2-21d9-410c-823e-c57bb0fb7fa4 fwd="109.173.154.199" dyno= connect= service= status=503 bytes= protocol=https
    

    Project tree:

    ├── Backend
    │   ├── AI
    │   │   ├── __init__.py
    │   │   ├── __pycache__
    │   │   │   ├── __init__.cpython-36.pyc
    │   │   │   ├── settings.cpython-36.pyc
    │   │   │   ├── urls.cpython-36.pyc
    │   │   │   └── wsgi.cpython-36.pyc
    │   │   ├── settings.py
    │   │   ├── urls.py
    │   │   └── wsgi.py
    │   └── manage.py
    ├── Dockerfile
    ├── init.sql
    ├── Frontend
    │   └── angularProject
            ├── Dockerfile
    │       └── all files in my angular project 
    ├── docker-compose.yml
    └── requirements.txt
    

    Frontend’s Dockerfile:

    # Create image based on the official Node 6 image from dockerhub
    FROM node:6
    
    # Create a directory where our app will be placed
    RUN mkdir -p /usr/src/app
    
    # Change directory so that our commands run inside this new directory
    WORKDIR /usr/src/app
    
    # Copy dependency definitions
    COPY package.json /usr/src/app
    
    # Install dependecies
    RUN npm install
    
    # Get all the code needed to run the app
    COPY . /usr/src/app
    
    # Expose the port the app runs in
    EXPOSE 4200
    
    # Serve the app
    CMD ["npm", "start"]
    

    Main directory’s Dockerfile:

    FROM python:3.6.1
    ENV PYTHONUNBUFFERED 1
    RUN mkdir /code
    WORKDIR /code
    ADD requirements.txt /code/
    RUN pip3 install -r requirements.txt
    ADD . /code/
    

    docker-compose.yml:

    version: '3'
    
    services:
      db:
        image: postgres
        environment:
          POSTGRES_USER: aso
          POSTGRES_PASSWORD: somepass
      django:
        build: .
        command: python3 MainDirectory/backend/myProject/manage.py runserver 0.0.0.0:8001
        volumes:
          - .:/code
        ports:
          - "8001:8001"
        depends_on:
          - db
      angular:
        build: MainDirectory/frontend
        ports:
          - "4200:4200"
        depends_on:
          - django
    

    init.sql:

    CREATE USER myUser;
    CREATE DATABASE myProject;
    GRANT ALL PRIVILEGES ON DATABASE myProject TO myUser;
    

  • nodejs server cannot link Redis and MongoDB in the same Docker-Compose yml file
  • “network not manually attachable” when running one-off command against docker swarm network
  • Docker private registry with mirror
  • docker: what is the similar url in docker as compared to XAMMP/MAMP
  • View dockerFile associated with tag
  • Configuring application in docker container to access other containers
  • 2 Solutions collect form web for “Deploying project in Docker with Angular 4, Django and postgresql”

    Looks to me you didn’t linked the containers where needed. If you want db to be visible by django add the links directive to your docker-compose.yml:

    ...
    
      django:
        build: .
        command: python3 MainDirectory/backend/myProject/manage.py runserver 0.0.0.0:8001
        volumes:
          - .:/code
        ports:
          - "8001:8001"
        depends_on:
          - db
        links:
          - db
    

    This way the db hostname will be resolved correctly. Hopefully.

    Hope this helps.

    You should use docker networks to link the containers together.

    Something like this:

    version: '3'
    
    services:
        db:
            image: postgres
            environment:
                POSTGRES_USER: aso
                POSTGRES_PASSWORD: somepass
            networks:
                - app
        django:
            build: .
            command: python3 MainDirectory/backend/myProject/manage.py runserver 0.0.0.0:8001
            volumes:
                - .:/code
            ports:
                - "8001:8001"
            networks:
                - app
            depends_on:
                - db
        angular:
            build: MainDirectory/frontend
            ports:
                - "4200:4200"
            networks:
                - app
            depends_on:
                - django
    networks:
        app:
    

    This allows you to more easily add and remove containers and services that need to communicate than links.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.