1 | initial version |
To set up MongoDB and Mongo-express using docker-compose, follow these steps:
First, create a folder on your computer where you want to store the docker-compose file and other files related to the setup.
Open a text editor and create a new file named docker-compose.yml in the folder you just created.
Copy and paste the following code into the docker-compose.yml file:
version: "3"
services:
mongo:
image: mongo
container_name: mongo
restart: always
ports:
- "27017:27017"
volumes:
- ./data:/data/db
mongo-express:
image: mongo-express
container_name: mongo-express
restart: always
ports:
- "8081:8081"
environment:
- ME_CONFIG_MONGODB_SERVER=mongo
Save the docker-compose.yml file and close the text editor.
Open a terminal and navigate to the folder where the docker-compose.yml file is located.
To start the containers, run the following command in the terminal:
docker-compose up -d
This will download the necessary images and start the MongoDB and Mongo-express containers in the background.
docker ps
This will show a list of running containers.
To access the Mongo-express web interface, open a web browser and go to http://localhost:8081. This should open the Mongo-express login page.
To stop the containers, run the following command in the terminal:
docker-compose down
This will stop and remove the containers.