dockerfile: Dockerfile ports: #We can access the API's like - 3090 :3090 volumes: #Map your system local project files and folders to docker container /usr/app. Services: mongo: #Container name of mongodb container_name: stackcoder-mongo #Docker image from image: mongo environment: #Default username, password and database of mongodb MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: root MONGO_INITDB_DATABASE: stackcoder ports: - 27017 :27017 volumes: #Adding volume makes sure that data is persistant and wont get deleted after your docker stops #Everytime this mongodb service starts data from your system mongo-data gets replicated to /data/db folder inside docker container - mongo-data:/data/db networks: #Adding network makes sure that we can operate with our API's like local setup - stackcoder api: #Container name of your API container_name: stackcoder-api #Since we are building image on our own we point to the Dockerfile path build: #Context tell the path to look for Dockerfile context. #Copy rest of the code to container COPY. NOTE: I have added comments in the Dockerfile and docker-compose.yml to make sure you understand each and every lineĭockerfile FROM node:18.12-slim WORKDIR /usr/app COPY. The following is the project structure of my ExpressJs application.ĭocker-compose.yml is used run multiple services and manage them with ease.ĭockerfile is used to create our custom docker image. Later we will see how we can access MongoDB from MongoDB Compass. In this article, let me walk you through how we can set up Docker to run NodeJs, and MongoDB like a breeze. In my latest project, I got a chance to work extensively on Docker. You might have configured your operating system-specific settings the same has to be shared with your colleagues, this will be an overhead in itself to manage all these settings and dependencies of your project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |