Using the database in docker

Environment: Under windows10, install vagrant and centOS-7 as virtual machines. Then install docker in the virtual machine and use it to install mongoDB

start up:

1. First open the Virtual software (just put it in the background), then find the vagrant installation location on the computer, cd to the directory in Windows cmd, run vagrant up, and start the virtual machine.

2. Run vagrant ssh to enter the virtual machine command environment. Enter su root to enter root

Enter service docker start to start docker

Enter docker pull mongo to pull the mongo image

Enter docker run --name cool-mongo -p 27017:27017 -d mongo to start mongoDB

At this point, you can verify whether mongoDB is started by docker container ps. My database name is cool-mongo

Enter the database docker exec -it cool-mongo bash, enter mongo to start the mongo command line client.


At this point we can process the database, such as: show dbs

If you want to stop mongo you can use the following command,


1
2
3
4
5
6
# 登入mongo
mongo
# 选择使用admin库,在其他的库不行
use admin
# 关闭mongo
db.shutdownServer()

By ‘ps -ef | grep momgo'checking whether the mongo process exists, if it does not exist, the shutdown is successful.





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324467265&siteId=291194637