Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 204
Dan Bolofe Avatar asked Mar 07 '26 12:03

Dan Bolofe


1 Answers

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
like image 68
atv Avatar answered Mar 10 '26 05:03

atv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!