Skip to content

Instantly share code, notes, and snippets.

@istepaniuk
Last active November 2, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save istepaniuk/2a3fc45a6ba7fe9d3447c0548fc0a294 to your computer and use it in GitHub Desktop.
Save istepaniuk/2a3fc45a6ba7fe9d3447c0548fc0a294 to your computer and use it in GitHub Desktop.
Docker command line cheatsheet

Docker cheatsheet

Run a new container in the foregrond

docker run -ti image

Stop, delete all docker containers

docker stop $(docker ps -a -q)

docker rm $(docker ps -a -q)

Exec bash inside a running container

docker exec -ti CONTAINER_ID bash

Exec bash inside the last run container

docker exec -ti $(docker ps -q |head -n1) bash

@TheoNeUpKid88
Copy link

TheoNeUpKid88 commented Nov 1, 2018

The "_Stop, Delete all docker containers section command: docker rm $(docker ps -a -q)_"

won't work. The -q option would relate to quitting an image. The correct formate to remove all images consecutively would be the following:

docker image rm $(docker images -a) --force

which would remove all images - the force option would just be an added measure if a container is being used or "dependent" on another image and/ or process. It also compounds the command to stop and remove all images which remove the need for the first command. - Thanks for the free resource

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