Dan Bolofe
Dan Bolofe

Reputation: 1139

Local development with docker - do I need 2 Dockerfiles?

Trying to dockerize a django project for the first time, I understand that for production my Dockerfile should have ADD that copies the django project to the container.

But for local development I need every change to the code to take effect immediately, for that I read it's recommended to mount a volume when I run docker ( docker run -v path:path ) but does that mean I need to have a different Dockerfile for local development? one that doesn't run the ADD command?

Upvotes: 3

Views: 235

Answers (3)

Dan Bolofe
Dan Bolofe

Reputation: 1139

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

Upvotes: 0

VonC
VonC

Reputation: 1327784

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

Upvotes: 0

atv
atv

Reputation: 2000

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

Upvotes: 5

Related Questions