Ask Your Question
4

What is the procedure for setting up MongoDB and Mongo-express using docker-compose?

asked 2022-09-27 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-02 17:00:00 +0000

woof gravatar image

To set up MongoDB and Mongo-express using docker-compose, follow these steps:

  1. First, create a folder on your computer where you want to store the docker-compose file and other files related to the setup.

  2. Open a text editor and create a new file named docker-compose.yml in the folder you just created.

  3. 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
  1. Save the docker-compose.yml file and close the text editor.

  2. Open a terminal and navigate to the folder where the docker-compose.yml file is located.

  3. 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.

  1. To verify that the containers are running, run the following command:
docker ps

This will show a list of running containers.

  1. 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.

  2. To stop the containers, run the following command in the terminal:

docker-compose down

This will stop and remove the containers.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-27 11:00:00 +0000

Seen: 10 times

Last updated: Apr 02 '23