feat: add filter functions for docker

This commit is contained in:
Yuanhao Ji 2024-07-14 14:33:53 +08:00
parent fd8f72b276
commit f6c06ebfc3
No known key found for this signature in database
GPG key ID: 1026820B3E5B996B
2 changed files with 52 additions and 37 deletions

View file

@ -41,40 +41,43 @@ zstyle ':omz:plugins:docker' legacy-completion yes
## Aliases ## Aliases
| Alias | Command | Description | | Alias | Command | Description |
| :------ | :---------------------------- | :--------------------------------------------------------------------------------------- | |:--------|:--------------------------------------------|:-----------------------------------------------------------------------------------------|
| dbl | `docker build` | Build an image from a Dockerfile | | dbl | `docker build` | Build an image from a Dockerfile |
| dcin | `docker container inspect` | Display detailed information on one or more containers | | dcin | `docker container inspect` | Display detailed information on one or more containers |
| dcls | `docker container ls` | List all the running docker containers | | dcls | `docker container ls` | List all the running docker containers |
| dclsa | `docker container ls -a` | List all running and stopped containers | | dclsa | `docker container ls -a` | List all running and stopped containers |
| dib | `docker image build` | Build an image from a Dockerfile (same as docker build) | | dib | `docker image build` | Build an image from a Dockerfile (same as docker build) |
| dii | `docker image inspect` | Display detailed information on one or more images | | dii | `docker image inspect` | Display detailed information on one or more images |
| dils | `docker image ls` | List docker images | | dils | `docker image ls` | List docker images |
| dipu | `docker image push` | Push an image or repository to a remote registry | | dipu | `docker image push` | Push an image or repository to a remote registry |
| dirm | `docker image rm` | Remove one or more images | | dirm | `docker image rm` | Remove one or more images |
| dit | `docker image tag` | Add a name and tag to a particular image | | dit | `docker image tag` | Add a name and tag to a particular image |
| dlo | `docker container logs` | Fetch the logs of a docker container | | dif | `docker images --filter "reference=*${1}*"` | List all images with the given name |
| dnc | `docker network create` | Create a new network | | dlo | `docker container logs` | Fetch the logs of a docker container |
| dncn | `docker network connect` | Connect a container to a network | | dnc | `docker network create` | Create a new network |
| dndcn | `docker network disconnect` | Disconnect a container from a network | | dncn | `docker network connect` | Connect a container to a network |
| dni | `docker network inspect` | Return information about one or more networks | | dndcn | `docker network disconnect` | Disconnect a container from a network |
| dnls | `docker network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts | | dni | `docker network inspect` | Return information about one or more networks |
| dnrm | `docker network rm` | Remove one or more networks | | dnls | `docker network ls` | List all networks the engine daemon knows about, including those spanning multiple hosts |
| dpo | `docker container port` | List port mappings or a specific mapping for the container | | dnrm | `docker network rm` | Remove one or more networks |
| dps | `docker ps` | List all the running docker containers | | dpo | `docker container port` | List port mappings or a specific mapping for the container |
| dpsa | `docker ps -a` | List all running and stopped containers | | dps | `docker ps` | List all the running docker containers |
| dpu | `docker pull` | Pull an image or a repository from a registry | | dpsa | `docker ps -a` | List all running and stopped containers |
| dr | `docker container run` | Create a new container and start it using the specified command | | dpsf | `docker ps --filter "name=${1}"` | List all running containers with the given name |
| drit | `docker container run -it` | Create a new container and start it in an interactive shell | | dpsfa | `docker ps --filter "name=${1}" -a` | List all running and stopped containers with the given name |
| drm | `docker container rm` | Remove the specified container(s) | | dpu | `docker pull` | Pull an image or a repository from a registry |
| drm! | `docker container rm -f` | Force the removal of a running container (uses SIGKILL) | | dr | `docker container run` | Create a new container and start it using the specified command |
| dst | `docker container start` | Start one or more stopped containers | | drit | `docker container run -it` | Create a new container and start it in an interactive shell |
| drs | `docker container restart` | Restart one or more containers | | drm | `docker container rm` | Remove the specified container(s) |
| dsta | `docker stop $(docker ps -q)` | Stop all running containers | | drm! | `docker container rm -f` | Force the removal of a running container (uses SIGKILL) |
| dstp | `docker container stop` | Stop one or more running containers | | dst | `docker container start` | Start one or more stopped containers |
| dtop | `docker top` | Display the running processes of a container | | drs | `docker container restart` | Restart one or more containers |
| dvi | `docker volume inspect` | Display detailed information about one or more volumes | | dsta | `docker stop $(docker ps -q)` | Stop all running containers |
| dvls | `docker volume ls` | List all the volumes known to docker | | dstp | `docker container stop` | Stop one or more running containers |
| dvprune | `docker volume prune` | Cleanup dangling volumes | | dtop | `docker top` | Display the running processes of a container |
| dxc | `docker container exec` | Run a new command in a running container | | dvi | `docker volume inspect` | Display detailed information about one or more volumes |
| dxcit | `docker container exec -it` | Run a new command in a running container in an interactive shell | | dvls | `docker volume ls` | List all the volumes known to docker |
| dvprune | `docker volume prune` | Cleanup dangling volumes |
| dxc | `docker container exec` | Run a new command in a running container |
| dxcit | `docker container exec -it` | Run a new command in a running container in an interactive shell |

View file

@ -34,6 +34,18 @@ alias dvprune='docker volume prune'
alias dxc='docker container exec' alias dxc='docker container exec'
alias dxcit='docker container exec -it' alias dxcit='docker container exec -it'
function dpsf {
docker ps --filter "name=${1}"
}
function dpsfa {
docker ps --filter "name=${1}" -a
}
function dif() {
docker images --filter "reference=*${1}*"
}
if (( ! $+commands[docker] )); then if (( ! $+commands[docker] )); then
return return
fi fi