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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With