[Django]-Local development with docker – do I need 2 Dockerfiles?

0👍

No need for 2 dockerfiles, if you mount with “docker run -v hostpath:containerpath” it mounts hostpath even if containerpath already exists!

5👍

No you may not need two files. You can use same folder in ADD command in volume.

See this django tutorial from official docker page:

https://docs.docker.com/compose/django/

Dockerfile

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

Compose file

version: '2'
services:
  db:
    image: postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
👤atv

0👍

Instead of binding a local folder to a container path, you could create a volume that can perists anywhere you want (as explained in this answer with the local persist pluging driver or even with a more advanced driver like flocker)

That way, your data persists in a data volume which can be accessed:

  • either locally (local persist plugin)
  • or still locally, through a dedicated container (svendowideit/samba/) mounting that volume
👤VonC

Leave a comment