Miles' Blog

天涯何處無幹話,何必要講實務話

Tricks

Official docker installation script :

curl -fsSL https://get.docker.com/ | sh

Stop all running container :

docker stop $(docker ps -a -q) 

Remove all containers :

docker rm $(docker ps -a -q)

You can add -f param to force delete all containers

Remove all images

docker rmi $(docker images -q)

You can add -f param to force delete all images, too

Remove all images without tag

docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

Remove all volumes

docker volume rm $(docker volume ls -qf dangling=true)

Show latest started container

docker ps -l
docker ps -n X

-l display only one container
-n display X latest containers

Show container logs

docker logs -f <CONTAINER_ID|CONTAINER_NAME>

-f param to follow the upcoming log messages. When you are done, hit CTRL+C
-t param display timestamp

Show container stats

docker stats [CONTAINER_ID|CONTAINER_NAME]

Without options, stats display all running containers
-a, --all display all containers

Enter in a container

docker exec -it [CONTAINER_ID|CONTAINER_NAME] bash

Docker 直接對應 app 的指令懶人包

# Docker Alias
alias composer="docker run -i -t --rm -v \$PWD:/app composer/composer:1.1-alpine"
alias npm="docker run -i -t --rm -v \$PWD:/usr/src/app -w /usr/src/app node:6.3-slim npm"
alias go="docker run -i -t --rm -v \$PWD:/usr/src/app -w /usr/src/app golang:1.6-alpine go"

References

0%