Skip to content

Instantly share code, notes, and snippets.

@tappoz
Last active August 29, 2019 15:28
Show Gist options
  • Save tappoz/2007dc8e4ae6e2e1ba6a83882463919d to your computer and use it in GitHub Desktop.
Save tappoz/2007dc8e4ae6e2e1ba6a83882463919d to your computer and use it in GitHub Desktop.
Docker and Virtual Machine cheat sheet

Docker

Building

If you have a Dockerfile in your project, then go to that folder e.g. /path/to/my/project then type docker build -t CONTAINER_NAME . where CONTAINER_NAME is a name of your choice.

Starting

docker start -p
docker pull host:port/something
docker run CONTAINER_NAME -P

Listing all the images

To list all the docker images in your repository: docker images.

Tiding up

To remove images that should not be needed anymore. The identifier 'none' appears as '' in the list of the command docker images.

  • Linux $ docker images --no-trunc | grep none | awk '{print $3}' | xargs -r docker rmi
  • MacOS $ docker images --no-trunc | grep none | awk '{print $3}' | xargs docker rmi

Alternative: $ docker images|awk '{print $1_":"_$2}'|xargs docker rmi

Alternative: $ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v /etc:/etc spotify/docker-gc

To remove containers with the Exit status.

  • Linux $ docker ps -a --no-trunc | grep 'Exit' | awk '{print $1}' | xargs -r docker rm
  • MacOS $ docker ps -a --no-trunc | grep 'Exit' | awk '{print $1}' | xargs docker rm

Recently a new list of commands has been provided:

  • docker system prune
  • docker container prune

Entering a container

docker exec -it e049bd80c225 bash

Restart boot2docker

The trick to fix the mess with certificates: boot2docker ssh 'sudo /etc/init.d/docker restart'

Finding the (local) IP address of a Docker container

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <CONTAINER_ID>

Virtual machines

Docker-machine restarting

docker ps -q > running_containers_ids.txt
docker-machine restart <VM_NAME>
while read DOCKER_CONTAINER_ID; do docker start "$DOCKER_CONTAINER_ID"; done < running_containers_ids.txt
rm running_containers_ids.txt

Alternative:

docker ps --no-trunc | grep -v 'CONTAINER' | awk '{print $1}' | xargs echo docker start

Docker-machine info

VBoxManage showhdinfo ~/.docker/machine/machines/<VM_NAME>/disk.vmdk
cat ~/.docker/machine/machines/<VM_NAME>/config.json | jq '.Driver.Memory'
VBoxManage showvminfo <VM_NAME>
VBoxManage modifyvm <VM_NAME> --memory 8000

Virtualbox network interfaces

Removing VirtualBox virtual adapters:

From the GUI: Preferences -> Network -> Host-only Network, remove vboxnet#

Command: VBoxManage hostonlyif remove vboxnet4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment