Home > Back-end >  docker django: Why to copy the context into docker image, if we are overwriting it by mounting somet
docker django: Why to copy the context into docker image, if we are overwriting it by mounting somet

Time:10-02

I was following the tutorial for docker and django. https://devopstuto-docker.readthedocs.io/en/latest/compose/django/django.html

I see the following docker file

FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/   <---- WHATS THE NEED OF THIS, SINCE WE ARE MOUNTING IT IN DOCKER COMPOSE

Docker compose file as

version: '3'

services:
  db:
    image: postgres
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code   <----------  WHY TO MOUNT THE CODE HERE. THE IMAGE HAS THE CODE
    ports:
      - "8000:8000"
    depends_on:
      - db

I see the in docker-compose.yml that its mounting the current folder into code - .:/code

and in the Dockerfile also we see ADD . /code/

Whats the need of ADD . /code/ if we are anyhow depend on the mounting in docker-compose which is going to overwrite the files

CodePudding user response:

there's no need for ADD . /code if you are using this docker-compose, this is used in local development

Dockerfile with ADD . /code results in an image with the django app you can run anywhere, this is used in deployment

  • Related