Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. # Mongo/Docker Cheatsheet
  2.  
  3. To download the latest image:
  4.  
  5. `$ docker pull mongo:latest`
  6.  
  7. To run a mongo container with detached mode(`-p`) and with ports mapped (`-p 27017-27017:27017-27019`) and named (`--name mongodb`):
  8.  
  9. `$ docker run -d -p 27017-27017:27017-27019 --name mongodb mongo:latest`
  10.  
  11. To list the docker images:
  12.  
  13. `$ docker images`
  14.  
  15. To stop a container:
  16.  
  17. `$ docker stop mongodb`
  18.  
  19. To remove a container:
  20.  
  21. `$ docker rm mongodb`
  22.  
  23. To list running containers:
  24.  
  25. `$ docker ps -a `
  26.  
  27. To enter an interactive terminal(`-it mongodb bash`):
  28.  
  29. `$ docker exec -it mongodb bash`
  30.  
  31. To login as a mongo client, enter a interactive terminal, then type:
  32.  
  33. `$ mongo`
  34.  
  35. To show the databases:
  36.  
  37. `> show dbs`
  38.  
  39. To switch to a database:
  40.  
  41. `> use <database>`
  42.  
  43. To save a record to the database:
  44.  
  45. `> db.people.save({firstname: "sean", lastname: "dittmar" })`
  46.  
  47. To show all records:
  48.  
  49. `> db.people.find({})`
  50.  
  51. To find a record using criteria:
  52.  
  53. `> db.people.find({firstname: "Sean"})`
  54.  
  55. To exit mongo:
  56.  
  57. `> quit`
  58.  
  59. To exit docker container:
  60.  
  61. `$ exit`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement