Home > Software engineering >  how let docker-compose detect my change of code
how let docker-compose detect my change of code

Time:12-24

as title. i find docker-compose can't detect my change of code ,even though i use --force-recreate.

the following is my dir structure.
root/
---docker-compose.yml
---/front/dockerFile
---/back/dockerFile

the following is my code.
docker-compose.yml

version: "3.9"
services:
  node:
    env_file: "./back/.env"
    volumes:
      - ./test:/backend/test
      - ./back/node_modules:/backend/node_modules
    build:
      context: ./back
    networks:
      - testNetwork
  next:
    depends_on:
      - node
    build:
      context: ./front
    ports:
      - "3000:3000"
    networks:
      - testNetwork
    volumes:
      - ./front/node_modules:/frontend/node_modules
      - ./test:/frontend/test
networks:
  testNetwork:

the following is my behavior.
1.use docker-compose up --force-recreate.
2.got some error.
3.try to change my code or dockerfile ,and save.
4.the same step 1.
5.but docker-compose can't detect my change of code.

is my process wrong?
and what's the efficient way to use docker-compose?
i feel my process is inefficiency.

thank you all.

CodePudding user response:

--force-recreate only re-create container from the existing image. What you need is rebuild the images after you made code changed by running docker-compose build, or docker-compose up --build.

  • Related