Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # brings the docker-machines env into my env (default machine)
- eval $(docker-machine env default)
- # restart machine if docker cannot connect to it
- docker-machine restart
- # create a machine
- docker-machine create --driver virtualbox default
- # run machine as daemon
- docker run -d --port 5432:5432 -name NAME_OF_CONTAINER
- dm ip # shows IP of container, also local
- # brings docker-machine ip into this env
- export MY_IP_ADDRESS=$(dm ip hello-world)
- docker build --tag MY_IMAGE_NAME . # dot for current dir
- docker build -P nginx # exports automatically all defined ports
- # lists all my docker images
- docker images
- # which docker images running
- docker ps
- # list containers you have
- docker ps -a
- # links two containers (db as db into mine)
- docker run --link db:db MY_IMAGE_NAME
- # inspect mode -i
- docker run -i -t --link db:db MY_IMAGE
- # starts the server
- docker run -i -t --link db:db MYIMAGE bin/rails server --port 3000 --binding 0.0.0.0
- # mount current directory onto running container FROM:TO
- docker run -v `pwd`:/MY_APP_FOLDER
- # set the working dir
- docker run -w /my/working/dir
- # map the user
- docker run -it --user "$(id -u):$(id -g)"
- # run ubuntu in an terminal and start bash
- docker run -it ubuntu:latest /bin/bash
- # run a db and map the volume to our existing database
- docker run -d --name cli_mongo -p 27017:27017
- # to prevent data loss when container changed: creates a
- docker run -d --name cli_mongo -p 27017:27017 -v mongo-db:/data/db mongo:latest
- # connect to an running container
- docker exec -it CONTAINER_NAME /bin/sh
- mongo
- #list volumes
- docker volume ls
- docker volume create --driver rexray --opt size=10 --name persistance
- docker network create --driver <NETWORKDRIVER> NAME
- # Delete all stopped containers
- docker rm $( docker ps -q -f status=exited)
- docker ps -q -f status=exited | xargs --no-run-if-empty docker rm
- #cleanup everything Docker Community Edition:
- docker system prune
- # docker-machine clear the volumes that are orphaned:
- docker volume rm $(docker volume ls -qf dangling=true)
- # Delete all dangling (unused) images
- docker rmi $( docker images -q -f dangling=true)
- docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi
- # Clean up dangling images:
- docker rmi $(docker images --quiet --filter "dangling=true")
- # Remove all containers (also running):
- docker rm -f $(docker ps -a -q)
- # Remove all images:
- docker rmi -f $(docker images -q)
- # 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:
- docker images -qf dangling=true | xargs docker rmi
- docker attach myContainer
- # To detach from a container and leave it running use CTRL-p CTRL-q.Then, attach to container2 and repeat these three commands.
- # Starts all stopped containers in the work directory
- docker-compose start
- # Stops all currently running containers in the work directory
- docker-compose stop
- # Validates and shows the configuration
- docker-compose config
- # Lists all running containers in the work directory
- docker-compose ps
- # Stops and removes all containers in the work directory
- docker-compose down
- # MYSQL EXAMPLE
- 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
- docker run --name myadmin -d --link mysql -p 80:88 -e PMA_HOST=mysql phpmyadmin/phpmyadmin
- # Create Volume Image connect Database Image and wordpress image
- docker create
- --name db-data
- -v /var/lib/mysql mysql:5.6 /bin/true
- docker create
- --name wp-data
- -v /var/www/html wordpress /bin/true
- docker run
- --name db-server -d
- -e MYSQL_ROOT_PASSWORD=Memzoh78
- -e MYSQL_DATABASE=wordpressdemo
- -e MYSQL_USER=conetixdemo
- -e MYSQL_PASSWORD=Xumkos26
- --volumes-from db-data mysql:5.6
- docker run
- --name wordpress-demo
- --link db-server:mysql -d
- -e WORDPRESS_DB_NAME=wordpressdemo
- -e WORDPRESS_DB_USER=conetixdodemo
- -e WORDPRESS_DB_PASSWORD=Xumkos26
- -p 8080:80
- --volumes-from wp-data wordpress
- docker run
- --volumes-from wp-data
- -v $(pwd):/backup ubuntu tar czf /backup/wordpress-backup.tar.gz /var/www/html
Add Comment
Please, Sign In to add comment