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.)

  • auto deploy to docker from nexus repo when maven project version changed
  • Docker images across multiple disks
  • Channgel Creation Failed. GRPC timeout
  • SSH into staging machine from docker instance using Bitbucket Pipelines
  • Nginx not redirect to https docker ports
  • Ruby Remote SDK configuration with Intellij broken - workarround?
  • dockerize c#.NET desktop application
  • How to run python scripts and do CMD in Dockerfile for the docker container
  • Failed to create the host-only adapter - windows 10, docker, virtualbox
  • Heroku-docker not working on osx
  • Is using linux containers (lxc) like docker is safe?
  • How is non-volume data for a Docker container stored?
  • 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.