0

stackoverflow:compose rebuild

everyone is telling docker composer up --build does rebuild, however I simply add a

console.log("example") inside my server.js, it does not reflect after docker compose up --build

Also, everytime I made some changes in my source code and try to rebuild , it never success connect to mongo db anymore.

And I must run all following commands to rebuild (but I want to persist my data in docker as well)

docker compose down
docker container rm nodejs-elliot 
docker container rm mongodd
docker image prune -a
y
docker volume prune
y
docker network prune
y
docker system prune -a
y
docker compose up --build

docker-compose.yml

version: "3.6"
services:
  easy-notes-app:
    container_name: nodejs-elliot
    image: elliotching/elliot-nodejs
    restart: always
    build: .
    ports:
      - "3003:3000"
    links:
      - mongo
  mongo:
    container_name: mongodd
    image: mongo
    # network_mode: host
    ports:
      - "28017:27017"
    volumes:
      - "mongodb_for_elliot_nodejs:/data/db"
volumes:
  mongodb_for_elliot_nodejs:

Dockerfile

FROM node:latest

WORKDIR /
COPY ./package.json ./package.json
COPY . .

RUN npm install

EXPOSE 3000
CMD [ "node", "./server.js" ]

4
  • Why would you need to constantly run builds? Just use docker-compose build to build your image, and use docker-compose up (the "loose" compose command is still experimental, don't rely on it to actually work yet). And if you need to do things like rebuilding things inside docker: that's what you do inside docker. E.g. apt-get updates, pip updates, npm updates, etc. are all things you "just do in your image". You don't rebuild it, you just treat it as a VM and have it run whatever scripts/commands update what you need updated inside the VM. Commented Mar 31, 2021 at 2:55
  • yes, even wihtout --build it doesn't reflect my source code changes as well. Do I need to docker push before compose? Commented Mar 31, 2021 at 2:56
  • And if you use docker-compose, not docker compose> Because the new standalone "compose" command is highly experimental and not guaranteed to work properly in the slightest. Commented Mar 31, 2021 at 3:08
  • The rebuild workflow described here is pretty typical. Unlike a VM, a container only runs a single process, and it's very normal to delete and recreate the container if the code changes. Commented Mar 31, 2021 at 11:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.