mongo remote connections open

Use docker deployment mongodb

  1.  
  2. docker pull mongo
  1.  
  2. docker run --name mongodb -v ~ /docker/mongo:/data/db -p 27017:27017 -d mongo
  1. Mirror Pull
  2. You can view mirror if the download was successful
    1.  
    2. docker images | grep mongo
    You should have the following display
    1.  
    2. mongo latest 7177e01e8c01 2 months ago 393MB
    > 2 months ago, and depending on the mirroring 393MB pulling time and the size of the corresponding version.
  3. Use docker installation mongodb
  4. After executing the command, a mirror mount mongo the container begins to run is provided wherein * `--name` name *` -v` container path set mapping to map the local path into the container. Here , the path may customize * `-p` set port mapping, will be mapped to the local 27017 (right) 27 017 (right side) of the container
  5. Into the container.
    1.  
    2. docker exec -it mongodb bash
    The above command following meanings: used in the form of interaction, this implementation `bash` command` mongodb` name of vessel
  6. Use of `mongodb`
    1. Users create and establish a database
    2. Create a user * Enter the following command into the `mongo`
      1.  
      2. mongo
      * Create user
      1.  
      2. # Enter the database admin
      3. use admin
      4. # Create an administrator user
      5. db.createUser(
      6. {
      7. user: "admin",
      8. pwd: "123456",
      9. roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
      10. }
      11. )
      12. # Create users can read and write permissions for a specific database, such as 'demo'
      13. db.createUser({
      14. user: 'test',
      15. pwd: '123456',
      16. roles: [{role: "read", db: "demo"}]
      17. })
      Establishment of the database
      1.  
      2. use demo;
    3. Mongo check whether the normal start
    4. A first write data
      1.  
      2. db.info.save({name: 'test', age: '22'})
      Check written data
      1.  
      2. db.info.find();
      The results are as follows
      1.  
      2. { "_id" : ObjectId("5c973b81de96d4661a1c1831"), "name" : "test", "age" : "22" }
      > Where `_id` should be different and author
  7. Remote connections open
  8. Among container `mongodb`
    1.  
    2. # Update source
    3. apt- get update
    4. # Install vim
    5. apt- get install vim
    6. # Mongo modify configuration files
    7. vim /etc/mongod.conf.orig
    Will be one of
    Bindip: 127.0.0.1
    Comment out the `# bindIp: 127.0.0.1` or changed to` bindIp: 0.0.0.0` to open a remote connection

Guess you like

Origin www.cnblogs.com/kofsony/p/12511728.html