3

Some helpful Docker commands

 3 years ago
source link: https://sj14.gitlab.io/post/2020/9-13-some-docker-bits/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
2020-09-13

Shell into a fresh container

Handy for some quick testing.

Debian

1
docker run -it debian /bin/bash

Alpine

1
docker run -it alpine /bin/ash

Stop all running containers

1
2
➜ docker stop $(docker ps -q)
fbcf1e74ffa0

Remove containers

Remove all stopped containers

1
2
➜ docker rm $(docker ps -aq)
fbcf1e74ffa0

Remove all stopped and running containers

1
2
3
➜ docker rm -f $(docker ps -aq)
42bb43d94321
ba382c0f060d

Docker System Prune

Clean up your host a bit.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
➜ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
a7125af23e4b403d3d0cd32f496a3ce03d81477edfc93250d724d74ed7af1261
4758fc7b6c39c804a6924049a07df0b0939121472c71eb02fc3ae89c35dbdc4e
ac6514650269a726c370a9eaec51e932e6423970fb010d3043ac8940c567bb47
...

Remove all Images

This is not done by docker system prune and gives your host machine some free space.

1
2
3
4
5
6
➜ docker rmi $(docker images -q)
Untagged: docker-cli-cross:latest
Deleted: sha256:c4d1b76915f6b20852c9cc7bbe8f7802701751790215911393b9155a981aa225
Deleted: sha256:33988b9a1a662863b21551a5e755621942d2c1f7889010e9dfba339e43619875
Deleted: sha256:39e372cfad76463c0ac8a75e173a3febb191c54e4b26358061423775fb9eb422
...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK