This project sets up a MongoDB instance using Docker and Docker Compose. It includes a Makefile
for managing the Docker setup, a docker-compose.yml
file for defining the services, a Dockerfile
for building the MongoDB image, and an example .env
file for environment variables.
- Docker 🐳
- Docker Compose 🛠️
-
Clone the repository:
git clone [email protected]:PepeCodeHub/MongoDB-docker.git cd MongoDB-docker
-
Copy the
.env.example
file to.env
and fill in the required environment variables:cp .env.example .env
make build
: Build the Docker image and run the containers. 🚀make up
: Start the containers without rebuilding. 🔄make down
: Stop and remove the containers. 🛑make logs
: View logs from the containers. 📜make ps
: Show running containers. 📋make clean
: Clean up unused Docker resources. 🧹make publish
: Tag and push the Docker image to Docker Hub. 📤make help
: Display available commands. ❓
The docker-compose.yml
file defines a single service:
db
: The MongoDB database service. 🗄️
The Dockerfile
builds a custom MongoDB image with the following stages:
- Build stage: Copies the initialization script.
- Final stage: Sets up the MongoDB environment, copies the initialization script, and starts MongoDB. 🐘
The .env
file should contain the following variables:
MONGO_INITDB_ROOT_USERNAME
: The username for the MongoDB root user. 👤MONGO_INITDB_ROOT_PASSWORD
: The password for the MongoDB root user. 🔑MONGO_DB
: The name of the initial database to create. 🗃️MONGO_USER
: The username for the MongoDB user. 👤MONGO_PASSWORD
: The password for the MongoDB user. 🔑DOCKER_USERNAME
: Your Docker Hub username. 🧑💻IMAGE_NAME
: The name of the Docker image. 🏷️TAG
: The tag for the Docker image. 🏷️
-
Build and start the containers:
make build
-
Start the containers without rebuilding:
make up
-
Stop and remove the containers:
make down
-
View logs from the containers:
make logs
-
Show running containers:
make ps
-
Clean up unused Docker resources:
make clean
-
Tag and push the Docker image to Docker Hub:
make publish
-
Display available commands:
make help
The Docker image is available on Docker Hub: f3an/mongo-docker-db
The Docker image is available on GitHub: f3an/postgresql-docker-db
MongoDB in Docker 🌿