Skip to content

Instantly share code, notes, and snippets.

@gyfoster
Last active January 13, 2021 17:08
Show Gist options
  • Save gyfoster/ea1be02d87045e36111a8582878386ed to your computer and use it in GitHub Desktop.
Save gyfoster/ea1be02d87045e36111a8582878386ed to your computer and use it in GitHub Desktop.
A list of commonly used Docker commands
List all containers:
$ docker ps -a
Get shell in running container:
$ docker exec -it <container name> /bin/bash
Stop a specific container:
$ docker stop <container-id>
Stop all running containers:
$ docker stop $(docker ps -a -q)
Remove all stopped containers:
$ docker rm $(docker ps -a -q)
List image:
$ docker images
Remove a specific image:
$ docker rmi <image-name-or-id>
Force remove all images:
$ docker rmi -f $(docker images -q)
Log into docker registry:
$ docker login nexus.my-domain.com:5000
Build image using current directory:
$ docker build -t my-project/<image-name> .
Start container and get log:
$ docker run -it --rm -p 8080:8080 my-project/<image-name>
Start container and get shell:
$ docker run -it --rm -p 8080:8080 my-project/<image-name> /bin/sh
$ docker run -it --rm -p 8080:8080 --entrypoint /bin/sh my-project/<image-name> # if entrypoint script already defined
Push image to registry:
$ docker tag my-project/<image-name>:latest nexus.my-domain.com:5000/my-project/<image-name>
$ docker push nexus.my-domain.com:5000/my-project/<image-name>:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment