1. Install Docker

Mac

  1. docker ( Run this command on terminal to check if docker is correctly installed )
  2. docker run -p 27017:27107 mongo ( Starting Docker Container for mongo )
  3. docker rmi <IMAGE_ID> —-force ( Removing docker image from your machine )
  4. docker ps ( Browses containers that are running currently )
  5. docker kill <CONTAINER_ID> ( To kill a container )
  6. docker images ( List all docker images present currently on your machine )
  7. Port Mapping
docker run -p 27018:27017 mongo
# mac's port : Docker container's port  ( Docker container's port for a process is defined in docker image of that process
  1. docker exec -it <CONTAINER_ID> ssh ( Now you are inside docker container ) can ls , cd to this machine

Containerizing a Node JS Project

.Dockerfile

# Base Docker Image which already has nodejs installed
FROM node:22-alpine

# Dir in Docker Container which will have all ur files and folders for ur project
WORKDIR /app

# Copy everything in this Directory to Docker Container
COPY . .

RUN npm install 

EXPOSE 3000

# Till here image is created

# When container starts what do u want to run
CMD ["node","index.js"]

  1. Command to build docker image locally
 docker build -t node-app-dockerimage .   
  1. Pushing docker image to hub.docker.com
# step 1 :
docker login # Login to your docker account

# step 2 : 
docker build -t ritikaxg/node-app-dockerimage . # If you build your image with your docker username you can push it to hub.docker.com

docker push ritikaxg/node-app-dockerimage # Pushing image to hub.docker.com

docker run -p 3000:3000 ritikaxg/node-app-dockerimage # Using this command anyone an start your process (docker image) at port 3000