It is a convenient tool for many Docker operations.
__ __ __ __
.--| |.-----.----.| |--.-----.----.______| |_.-----.-----.| |
| _ || _ | __|| <| -__| _|______| _| _ | _ || |
|_____||_____|____||__|__|_____|__| |____|_____|_____||__|
dt (docker-tool)
Usage:
sudo ./docker-tool <action> [args...]
Actions:
clean-img | Clean dangling images
clean-vol | (DANGEROUS!!!) Clean dangling volumes, who are not referenced by any containers
clean-container | Remove exited containers
img [name] | Grep image by given <name>
logs <container-id/name> | == docker logs --tail=50 -f <container-id/name>
net <container-id/name> | Show network info (mode, veth pair, ...) of a container
ns-net <container-id/name> | Enter the net namespace of a container, with all host's tools available. Use "exit" to exit
pid <container-id/name> | Get the pid of a container
ps [-a] [name] | Grep from docker ps
run ... | == docker run -it --rm ...
ssh <container-id/name or image> | Enter the bash/sh of a container or image
config [-l|--list] <key> <value> | config docker-tool, save under /etc/docker-tool/ (available keys: tag-prefix)
| '-l', '--list' to show all the current configurations.
tag [-p] [--rm] <image> | tag the image by configured prefix.
| '-p' to push the new image after tagging it.
| '--rm' to remove the new local image after pushing it. (must use --rm with -p)
Other actions:
clean-k8s | Clean dangling k8s containers
self-upgrade | Upgrade "docker-tool" to the latest version
INSTALL_DIR='/usr/local/bin'
sudo curl -o ${INSTALL_DIR}/docker-tool https://raw.githubusercontent.com/ohmystack/docker-tool/master/docker-tool
sudo chmod a+x ${INSTALL_DIR}/docker-tool
sudo ln -sf ${INSTALL_DIR}/docker-tool ${INSTALL_DIR}/dt
You can use command-line docker-tool
or dt
for short.
Upgrade:
dt self-upgrade
dt ssh
This is not a real "ssh", but most users want such kind of experience.
It is complicated to do this without this tool, you will type
docker exec -it xxx /bin/bash
, and then find that there is nobash
in the container, then change tosh
. Or, typedocker run -it --rm --entrypoint /bin/bash xxx
to get into an image.
dt ssh <image>
dt ssh <container>
- Images:
dt img
dt img <keyword>
- Containers:
dt ps
dt ps <keyword>
dt ps -a <keyword>
dt logs
Short for docker logs --tail=50 -f <container-id/name>
.
dt logs <container-name>
dt pid
Get the pid of a container.
dt pid <container-name>
dt clean-img
Clean the dangling images. May save lots of your disk space.
dt clean-container
Clean the exited containers.
dt clean-vol
Clean the dangling volumes.
dt net
Get the network type and info.
You can even get the veth pair info of a container if it is using the "default" NetworkMode. This is very helpful when debugging the network.
dt ns-net
Enter the network namespace of a container.
So that you can use the utils installed on your server to debug the container inside network.
If you have any good ideas about docker-tool
, welcome to submit your PRs.
One simple rule: Keep this docker-tool
a single file bash program.