Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.2K
Visualizações
How can I make my docker container update on changes to my source files?

I'm building a Django/React app using docker-compose, and I'd like it to reload my apps when a change is made, so far I've tried adding CHOKIDAR_USEPOLLING, adding npm-watch to my package.json, but it doesn't seem to be able to detect changes in the host file.

Ideally I don't want to have to run docker-compose up --build every time I make a change since it's making development tedious.

edit: I should mention that the apps both reload running outside of docker (npm start (cra default) and python manage.py runserver) as expected.

Changes are detected inside the container, but the react app will not rebuild.

I'm using Windows 10 also.

Is there something wrong with my files or something else I should be doing here?

docker-compose.yml

version: "3.9"
   
services:
  db:
    container_name: db
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
  backend:
    container_name: backend
    build: ./backend
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/core
    ports:
      - "8000:8000"
    depends_on:
      - db
  frontend:
    container_name: frontend
    build: ./frontend
    command: npm start
    volumes:
      - './frontend:/app/'
      - '/frontend/node_modules'
    ports:
      - "3000:3000"
    environment:
      - CHOKIDAR_USEPOLLING=true
    depends_on:
      - backend
    # Enable interactive terminal (crucial for react container to work)
    stdin_open: true 
    tty: true

backend Dockerfile

FROM python:3 
ENV PYTHONUNBUFFERED=1
WORKDIR /code/
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

frontend Dockerfile

FROM node:16

WORKDIR /app/

COPY package*.json /app/

RUN npm install

COPY . /app/

EXPOSE 3000

CMD ["npm", "start"]
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Instead of copying you should mount volumes directly to the folder where you run the code on your docker image. In that way your code changes will be reflected in your app.

Example in docker-compose.yml:

volumes:
      - "local_source_destination:/server_source_destination"

In your frontend docker-compose-yml you have:

    volumes:
  - '.:/frontend/app'

but in your Dockerfile your have

COPY . /app/

So it seems like your are mixing up where to mount your volume. Make sure '.' is where your root of your code folder is or change it accordingly.

Try something like:

 volumes:
  - '.:/app'

As that seems to be the location your server wants your code to be.

If your code is correctly mounted to the right destination it might be that you are not running your watch script from inside the docker container. Try running:

docker exec -itw source_destination_in_container your_container_name command_to_run_watch
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda