Skip to content

Latest commit

 

History

History
105 lines (83 loc) · 1.96 KB

comamnds.md

File metadata and controls

105 lines (83 loc) · 1.96 KB

Helpful Docker Commands

Made to quickly copy and paste commands.

Docker

Containers

Stop all containers:

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

Remove all containers:

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

Remove all exited containers:

$ docker rm $(docker ps -a -f status=exited -q)

Stop & Remove all containers:

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

View logs of a conatainer:

Replace <container> with name or id of container your want to view the logs of.

$ docker logs -f <container>

Execute on a container:

Replace <container> with name or id of container your want to execute a command on. Replace <command> with the command you want to execute.

$ docker exec <container> <command>

Execute on a container: (Interactive)

Replace <container> with name or id of container your want to execute a command on.

$ docker exec -it <container> sh
$ docker exec -it <container> bash

Images

Remove all dangling images:

$ docker rmi $(docker images -f dangling=true -q)

Remove all images: (Force)

$ docker rmi -f $(docker images -a -q)

Remove all images:

$ docker rmi $(docker images -a -q)

Build a tagged image:

$ docker build --tag image-name:latest .

Volumes

Remove all dangling volumes:

docker volume rm $(docker volume ls -f dangling=true -q)

Registry

Login to Docker registry:

$ docker login -u user -p pass registry.example.com

Push image to remote registry: (Must login first)

$ docker push image-name:latest

Docker hub

Login to docker hub

$ docker login -u user -p pass

Commit containers

$ docker commit <container ID> <repo name>/<Name you want to give the image>

Push to docker hub

$ docker push <repo name>/<Name you gave the image>