Reputation: 1139
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
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
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:
svendowideit/samba/
) mounting that volumeUpvotes: 0
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