1024programmer Java Docker practice (7) Installing mongo

Docker practice (7) Installing mongo


Installed docker, If it is not installed, please click this installation tutorial

Start the installation

You can first check the latest version information of mongo on docker hub
Enter mongo
Insert picture description here

Click to enter View support The tags, is the version number
Insert picture description here

  1. Pull the image

I pull the latest version directly here

[root@mq0 ~]# docker pull mongo:latest#You can also directly pull the version number without the version number,that is, the latest version
[root@mq0 ~]# docker pull mongo# View images
[root@localhost ~]# docker images
mongo latest ba0c2ff8d362 2 days ago 492MB

  1. Run image

# 1. Run mongdbdocker run -d -p 27017:27017 -- name mymongo mongo ---No permissions required docker logs -f mymongo --View mongo running log# 2. Enter the mongo containerdocker exec -it mymongo /bin/bash Directly execute the mongo command to operate # 3. Common containers with permissions docker run --name mymongo -p 27017:27017 -d mongo --auth# 4. Enter the container to configure the username and passwordmongouse admin and select the admin library db.createUser({user:"root",pwd:"root", roles:[{role:'root',db:'admin'} ]}) //Create a user. If this user is created successfully, subsequent operations require user authentication. exit# 5. Map the data directory in mongo to the host docker run -d -p 27017:27017 - v /root/mongo/data:/data/db --name mymongo mongo

Parameter explanation:
–name: alias
-v /root /mongo/data:/data/db data file is mounted to the host
-p maps the port in the container
-d: daemon thread (background)running&# xff0c;Abbreviation of daemon

View startup log

[ root@192 ~]# docker logs -t -f container id|container name

  1. Interface access
    Insert picture description here
    Connection successful!!!

If this article can be helpful to you, please don’t forget to click Like and collect~

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/746491

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top