This repository is created as part of our journey to learn Docker from scratch. We started exploring Docker to simplify development, deployment, and environment management using containers. Here, you'll find basic examples, Dockerfiles, Compose setups, and real-world use cases that helped us understand how Docker works in practice.
# docker compose -f mongodb.yaml up -d => start the containers in detached mode# docker compose -f mongodb.yaml down => stop the containersversion: "3.8"# optional, specify the version of the docker-compose file formatservices:
mongo:
image: mongoports:
- "27017:27017"environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME} # MONGO_INITDB_ROOT_USERNAME: username
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
- MONGO_INITDB_DATABASE=${MONGO_DB}volumes:
- /c/Users/path-dir/Desktop/data:/data/db # persist data in a named volume (host_directory:/container_directory) (mongodb data path = /data/db)mongo-express:
image: mongo-expressports:
- "8081:8081"depends_on:
- mongoenvironment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_USERNAME}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_PASSWORD}
- ME_CONFIG_MONGODB_SERVER=mongo
Create Dockerfile
# Build a Docker image for a Node.js application with MongoDB# Command to build the image: docker build -t <your-dockerhub-username>/testapp .# Command to push the image to Docker Hub: docker push <your-dockerhub-username>/testapp# Use an official Python runtime as a parent imageFROM node
# Define environment variableENV MONGODB_USERNAME=admin \
MONGODB_PASSWORD=password
# Install any needed packages specified in requirements.txtRUN mkdir -p textapp
# Copy the current directory contents into the container at /appCOPY . /textapp
# Run app.py when the container launchesCMD ["node", "/textapp/server.js"]