Skip to content

Instantly share code, notes, and snippets.

@rafaelune
Last active December 17, 2019 19:05
Show Gist options
  • Save rafaelune/8a3afcadfb4af6ab9ab7 to your computer and use it in GitHub Desktop.
Save rafaelune/8a3afcadfb4af6ab9ab7 to your computer and use it in GitHub Desktop.
Docker cheat sheet

Images

Lists images

$ docker images

Removes an image

$ docker rmi <image-id>

Removes all images

$ docker rmi $(docker images -q)

Search for images

$ docker search <search-term>

Containers

List runing containers

$ docker ps

Lists all containers

$ docker ps -a

Retrieves logs present at the time of execution

$ docker logs

Runs container in interactive mode

$ docker run -ti <image-name> bash

Stops a container

$ docker stop <container-id>

Stop all containers

$ docker stop $(docker ps -a -q)

Removes a container

$ docker rm <container-id>

Remove all containers

$ docker rm $(docker ps -a -q)

Volume a folder in host to container

$ docker run -v ~/host-folder:/container-folder ubuntu

Exposes container 8080 to host 8080 host:container

$ docker run -p 8080:8080 <image-name>

Detach container (does not stop the container) 'Ctrl-p' + 'Ctrl-q'

Build a Dockerfile

$ docker build -t <alias-name> .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment