How to deploy MongoDB container with Docker

How to deploy MongoDB container with Docker

What is Docker

"Docker is an open source application container engine that allows developers to package their applications and dependent packages into a portable container and then publish it to any popular Linux machine. It can also achieve virtualization. The container is completely sandboxed and there is no interface between them."

MongoDB is a free, open source, cross-platform, document-oriented NoSQL database program.

Here is a detailed tutorial on how to deploy MongoDB with Docker.

deploy

1. Pull the image

Here we pull the latest version of the image

docker pull mongo:latest 

insert image description here

2. View the image

As you can see in the picture, the latest version of the mongo image has been installed.

 docker images 

insert image description here

3. Run the container

After the installation is complete, you can use the command to run the mongo container, and finally view the container running information through the docker ps command

docker run -itd --name mongo -p 27017:27017 mongo --auth 

insert image description here

-p 27017:27017: Maps the container service port 27017 to the host port 27017. The outside world can directly access the mongo service through the host ip:27017.
–auth: A password is required to access the container service.

4. Create a User

Then enter the mongo container, add user admin 12345678, and log in to see if the creation is successful.

docker exec -it mongo mongo admin
db.createUser({ user:'admin',pwd:'12345678',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
db.auth('admin', '12345678') 

insert image description here

5. Connect to DB

First enter the mongo container, log in as user admin 12345678, and execute show dbs to view the database. At this time, mongo has been deployed successfully.

docker exec -it mongo mongo admin
db.auth('admin', '12345678')
show dbs 

insert image description here

6. UI

Next, we use the UI interface to access MongoDB, enter the link information, and the connection will be successful.

insert image description here

insert image description here

The above is the details of deploying MongoDB with Docker. For more information about deploying MongoDB with Docker, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Implementation steps for docker deployment of springboot and vue projects
  • Detailed process of installing and deploying onlyoffice in docker
  • Complete steps for deploying confluence with docker
  • How to deploy code-server using docker

<<:  Summary of MySQL 8.0 Online DDL Quick Column Addition

>>:  Discussion on the problem of garbled characters in iframe page parameters

Recommend

Simple usage examples of MySQL custom functions

This article uses examples to illustrate the usag...

Detailed explanation of creating and calling MySQL stored procedures

Table of contents Preface Stored Procedure: 1. Cr...

MySQL cursor detailed introduction

Table of contents 1. What is a cursor? 2. How to ...

More than 100 lines of code to implement react drag hooks

Preface The source code is only more than 100 lin...

Vue code highlighting plug-in comprehensive comparison and evaluation

Table of contents Comprehensive comparison From t...

Shorten the page rendering time to make the page run faster

How to shorten the page rendering time on the bro...

How to manually deploy war packages through tomcat9 on windows and linux

The results are different in Windows and Linux en...

Thinking about grid design of web pages

<br />Original address: http://andymao.com/a...

Douban website's method for making small changes to website content

<br />Reading is a very important part of th...

How to modify Ubuntu's source list (source list) detailed explanation

Introduction The default source of Ubuntu is not ...

202 Free High Quality XHTML Templates (2)

Following the previous article 202 Free High-Qual...