What is the correct way to set up a Django/PostgreSQL project with Docker Compose?

Can you tell me what is the best way to way to set up and configure a Django/PostgreSQL project with Docker Compose?

(with the latest versions of everything, python 3.4, django 1.8.1, etc.)

  • How do I make Docker 'type'?
  • Why is networking so slow in this Fig/Docker container?
  • docker-compose error when I run bundle
  • Jenkins-node as docker container
  • Bulk Container image pull without “docker pull”
  • Deleting devicemapper after changing storage driver
  • blktrace output error in docker container
  • What is the relation between docker0 and eth0?
  • What are Selenium Docker image release versions for browser capabilities?
  • Can docker “instance” run totally in ram?
  • How to intercept the request from Spring Interceptor to Node Service
  • Access Wildfly-Docker-Container from Apache-Docker-Container
  • One Solution collect form web for “What is the correct way to set up a Django/PostgreSQL project with Docker Compose?”

    Have you looked at the examples on the Docker website? Here’s a link describing exactly this.

    Basically, you need two services, one for your Django app and one for your Postgres instance. You would probably want to build a Docker image for your Django app from you current folder, hence you’ll need to define a Dockerfile:

    # Dockerfile
    FROM python:3.4-onbuild

    That’s the whole Dockerfile! Using the magic -onbuild image, files are automatically copied to the container and the requirements are installed with pip. For more info, read here.

    Then, you simply need to define your docker-compose.yml file:

    # docker-compose.yml
      image: postgres
      build: .
      command: python manage.py runserver
        - .:/code
        - "8000:8000"
        - db

    Here, you’ve defined the Postgres service, which is built from the latest postgres image. Then, you’ve defined your Django app’s service, built it from the current directory, exposed port 8000 so that you can access it from outside your container, linked to the database container (so that they can magically communicate without anything specific from your side – more details here) and started the container with the classic command you use to normally start your Django app. Also, a volume is defined in order to sync the code you’re writing with the one from inside your container (so that you don’t need to rebuild your image every time you change the code).

    Related to having the latest Django version, you just have to specify it in your requirements.txt file.

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