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

Use iframe to display weather effects on web pages

CSS: Copy code The code is as follows: *{margin:0;...

Master-slave synchronization configuration of Mysql database

Table of contents Mysql master-slave synchronizat...

Similar to HTML tags: strong and em, q, cite, blockquote

There are some tags in XHTML that have similar fu...

React new version life cycle hook function and usage detailed explanation

Compared with the old life cycle Three hooks are ...

18 Web Usability Principles You Need to Know

You can have the best visual design skills in the...

Use pure CSS to achieve scroll shadow effect

To get straight to the point, there is a very com...

Deploy Varnish cache proxy server based on Centos7

1. Varnish Overview 1. Introduction to Varnish Va...

Reasons and solutions for prompting to save action after uploading files in form

The json data must be returned in html format That...

Index Skip Scan in MySQL 8.0

Preface MySQL 8.0.13 began to support index skip ...