Connect Node to MongoDB with Docker and Docker Compose

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 11

  • @tabdig
    @tabdig 7 місяців тому +4

    great video, thanks!

  • @stefanbogdanovic590
    @stefanbogdanovic590 7 місяців тому +1

    Can we add dockerignore and ignore node_modules, beacuse there are some OS specific packages that won't work for docker container, so that we don't have to use volumes for node_modules? Amazing video BTW

    • @WittCode
      @WittCode  7 місяців тому +2

      Hey there! Completely forgot about adding dockerignore to this... However I had to make a node_modules volume as I created a volume that brings the entire server code (package.json, node_modules, src, and all) into the container. Because of this I don't think placing node_modules in dockerignore would prevent it from being copied over but I could be wrong... I think .dockerignore is only for copying code over with COPY and not volumes?

  • @thom4989
    @thom4989 5 місяців тому +1

    Nice vid. Would adding node_modules to a .dockerignore file cover the problem with installing the incorrect binaries? Inside the Dockerfile, when specifying `RUN npm install`, would it not then install the correct modules for the given container (20-Alpine)? And therefore remove the need for a node_modules volume? Thanks

    • @WittCode
      @WittCode  5 місяців тому +2

      Hey there thanks! It wouldn't in this case as the volume I made is copying the entire application into the container. The dockerignore file is for ignoring things at build time! Volumes are applied at runtime so it would overwrite the node_modules created in the build step.

  • @mehmetyilmaz001
    @mehmetyilmaz001 Місяць тому

    This a very helpful video many thanks! I did the same but got the error "MongoDB connection error: MongoServerError: Authentication failed."

    • @WittCode
      @WittCode  Місяць тому

      No worries thanks for watching! Did you check your environment variables for the Mongo image? They set the Mongo auth!

  • @mujibulhaquetanim
    @mujibulhaquetanim 7 місяців тому

    Thank you for the tutorial. However, I prefer not to dockerize my Node application or install MongoDB on my system. Could you guide me on how to access MongoDB from Docker with my Node application, similar to how I would with MongoDB Atlas?

    • @WittCode
      @WittCode  7 місяців тому

      Hey there thanks! I don't have Mongo installed on my system as I'm using Docker like in the video. If you have Node installed locally and you want to connect just connect your Node app to the port you have mapped from your machine to the Mongo Docker container.

  • @localhost5000Leo
    @localhost5000Leo Місяць тому

    Why mongodb ? why not mongoose ?