Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

772
Views
Why does docker-compose build not reflect my django code changes?

So I have a Django project I am deploying with docker-compose. There is a simple error in my profile_form.html template with line 3 highlighted.

{% include "header.html" %}
{% load i18n %}
{% load url from future %}

'future' is not a registered tag library

So I simple delete the load url line, save profile_form.html, and then try to build a new container reflecting the code change.

docker-compose build
docker-compose start

This did not resolve the issue and I get the same error. I went into the container by running

docker-compose exec -i -t <containerid> /bin/bash

and examined the profile_form.html and sure enough line 3 is still there.

Unless I am missing something completely obvious this tells me that my understanding of docker-compose build is incorrect. As I thought docker-compose build would be able to determine "yes there is a code change in the 'web' directory" and then rebuild the container.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You do not need to rebuild a docker image, which is used for development, on each change of your code. This would take too much time. But since you are developing django and I assume, that you are using the dev-server shipped with django (python manage.py runserver), you can directly send your new code changes to your container and let the dev-server hot load the code as you are used to when you are developing a django application on your local machine. You need to map a volume from your host to your container, which receives the latest code and uses it to update your application.

Since you did not provide any code samples, I can only guess what you are doing. Take a look at the example directly provided by the docker developers: https://docs.docker.com/compose/django/

Their 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/

ADD . /code/ initially copys your local code to the container. This is the initial state of your application when you build the image for the first time. But we do not want to build the image on each code change, since this takes some minutes. You are using docker-compose and you can map volumes to your container for hot code reloading as it can be seen in the tutorial by the docker devs:

version: '2'
services:
  db:
    image: postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code  # <--  THIS line enables hot code reloading!
    ports:
      - "8000:8000"
    depends_on:
      - db

I marked the important line for code reloading. This line ensures, that each change on your local machine is also reflected inside the container. The dev-server runserver recognizes the local code change and restarts the webserver, which takes only few seconds.

This is the way to go with a django application inside a docker container.

Why are there no changes after running docker-compose start?

docker-compose start starts the old containers of your old image with the wrong line in your code. You need to create new containers with the new image. For this case is the command docker-compose up. From the docs of docker-compose start:

Usage: start [SERVICE...]
Starts existing containers for a service.

To be sure, you can remove your old containers with docker-compose rm. This removes only your containers, not the image.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!