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" ]
docker-compose buildto build your image, and usedocker-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.--buildit doesn't reflect my source code changes as well. Do I need todocker pushbefore compose?docker-compose, notdocker compose> Because the new standalone "compose" command is highly experimental and not guaranteed to work properly in the slightest.