Guest User

Untitled

a guest
Apr 9th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. # brings the docker-machines env into my env (default machine)
  2. eval $(docker-machine env default)
  3. # restart machine if docker cannot connect to it
  4. docker-machine restart
  5. # create a machine
  6. docker-machine create --driver virtualbox default
  7. # run machine as daemon
  8. docker run -d --port 5432:5432 -name NAME_OF_CONTAINER
  9. dm ip # shows IP of container, also local
  10. # brings docker-machine ip into this env
  11. export MY_IP_ADDRESS=$(dm ip hello-world)
  12. docker build --tag MY_IMAGE_NAME . # dot for current dir
  13. docker build -P nginx # exports automatically all defined ports
  14. # lists all my docker images
  15. docker images
  16. # which docker images running
  17. docker ps
  18. # list containers you have
  19. docker ps -a
  20. # links two containers (db as db into mine)
  21. docker run --link db:db MY_IMAGE_NAME
  22. # inspect mode -i
  23. docker run -i -t --link db:db MY_IMAGE
  24. # starts the server
  25. docker run -i -t --link db:db MYIMAGE bin/rails server --port 3000 --binding 0.0.0.0
  26. # mount current directory onto running container FROM:TO
  27. docker run -v `pwd`:/MY_APP_FOLDER
  28. # set the working dir
  29. docker run -w /my/working/dir
  30. # map the user
  31. docker run -it --user "$(id -u):$(id -g)"
  32. # run ubuntu in an terminal and start bash
  33. docker run -it ubuntu:latest /bin/bash
  34. # run a db and map the volume to our existing database
  35. docker run -d --name cli_mongo -p 27017:27017
  36. # to prevent data loss when container changed: creates a
  37. docker run -d --name cli_mongo -p 27017:27017 -v mongo-db:/data/db mongo:latest
  38. # connect to an running container
  39. docker exec -it CONTAINER_NAME /bin/sh
  40. mongo
  41.  
  42. #list volumes
  43. docker volume ls
  44. docker volume create --driver rexray --opt size=10 --name persistance
  45.  
  46. docker network create --driver <NETWORKDRIVER> NAME
  47. # Delete all stopped containers
  48. docker rm $( docker ps -q -f status=exited)
  49. docker ps -q -f status=exited | xargs --no-run-if-empty docker rm
  50.  
  51. #cleanup everything Docker Community Edition:
  52. docker system prune
  53. # docker-machine clear the volumes that are orphaned:
  54. docker volume rm $(docker volume ls -qf dangling=true)
  55. # Delete all dangling (unused) images
  56. docker rmi $( docker images -q -f dangling=true)
  57. docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi
  58. # Clean up dangling images:
  59. docker rmi $(docker images --quiet --filter "dangling=true")
  60. # Remove all containers (also running):
  61. docker rm -f $(docker ps -a -q)
  62. # Remove all images:
  63. docker rmi -f $(docker images -q)
  64.  
  65. # It will give you an error if there’s no dangling image present. If you don’t want that, then this might work for you:
  66. docker images -qf dangling=true | xargs docker rmi
  67.  
  68. docker attach myContainer
  69. # To detach from a container and leave it running use CTRL-p CTRL-q.Then, attach to container2 and repeat these three commands.
  70.  
  71.  
  72. # Starts all stopped containers in the work directory
  73. docker-compose start
  74. # Stops all currently running containers in the work directory
  75. docker-compose stop
  76. # Validates and shows the configuration
  77. docker-compose config
  78. # Lists all running containers in the work directory
  79. docker-compose ps
  80. # Stops and removes all containers in the work directory
  81. docker-compose down
  82.  
  83.  
  84.  
  85. # MYSQL EXAMPLE
  86. docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=user -e MYSQL_PASSWORD=user -e MYSQL_DATABASE=mydatabase
  87. docker run --name myadmin -d --link mysql -p 80:88 -e PMA_HOST=mysql phpmyadmin/phpmyadmin
  88.  
  89.  
  90. # Create Volume Image connect Database Image and wordpress image
  91. docker create
  92. --name db-data
  93. -v /var/lib/mysql mysql:5.6 /bin/true
  94.  
  95. docker create
  96. --name wp-data
  97. -v /var/www/html wordpress /bin/true
  98.  
  99. docker run
  100. --name db-server -d
  101. -e MYSQL_ROOT_PASSWORD=Memzoh78
  102. -e MYSQL_DATABASE=wordpressdemo
  103. -e MYSQL_USER=conetixdemo
  104. -e MYSQL_PASSWORD=Xumkos26
  105. --volumes-from db-data mysql:5.6
  106.  
  107. docker run
  108. --name wordpress-demo
  109. --link db-server:mysql -d
  110. -e WORDPRESS_DB_NAME=wordpressdemo
  111. -e WORDPRESS_DB_USER=conetixdodemo
  112. -e WORDPRESS_DB_PASSWORD=Xumkos26
  113. -p 8080:80
  114. --volumes-from wp-data wordpress
  115.  
  116. docker run
  117. --volumes-from wp-data
  118. -v $(pwd):/backup ubuntu tar czf /backup/wordpress-backup.tar.gz /var/www/html
Add Comment
Please, Sign In to add comment