This is a plugin that allows you to execute Docker commands using keyboard shortcuts, based on MartinRamm/fzf-docker
and utilizing fzf
and docker
.
Install fzf using Homebrew
brew install fzf
Please refer to the fzf official documentation for installation instructions on other operating systems.
wget -O ~/.fzfdocker https://raw.githubusercontent.com/gumob/fzf-docker/main/fzf-docker.sh
Source fzf
and fzfdocker
in your run command shell.
By default, no key bindings are set. If you want to set the key binding to Ctrl+K
, please configure it as follows:
Set the key binding for fzf-docker and load the script.
cat <<EOL >> ~/.zshrc
export FZF_DOCKER_KEY_BINDING="^D"
source ~/.fzfdocker
EOL
~/.zshrc
should be like this.
source <(fzf --zsh)
export FZF_DOCKER_KEY_BINDING='^D'
source ~/.fzfdocker
Source run command
source ~/.zshrc
Set the key binding for fzf-docker and load the script.
cat <<EOL >> ~/.bashrc
export FZF_DOCKER_KEY_BINDING='\C-d'
source ~/.fzfdocker
EOL
~/.bashrc
should be like this.
eval "$(fzf --bash)"
export FZF_DOCKER_KEY_BINDING='\C-d'
source ~/.fzfdocker
Source run command
source ~/.bashrc
To run fzf-docker
without using a keyboard shortcut, remove the line export FZF_DOCKER_KEY_BINDING='key-combination'
from the run command and enter the following command in the shell.
fzf-docker
description | fzf mode | command arguments (optional) |
---|---|---|
docker restart && open logs (in follow mode) | multiple | |
docker logs (in follow mode) | multiple | time interval - e.g.: 1m for 1 minute - (defaults to all available logs) |
docker logs (in follow mode) all containers | time interval - e.g.: 1m for 1 minute - (defaults to all available logs) |
|
docker exec in interactive mode | single | command to exec (default - see below) |
docker remove container (with force) | multiple | |
docker remove all containers (with force) | ||
docker stop | multiple | |
docker stop all running containers | ||
docker stop and remove container | multiple | |
docker stop and remove all container | ||
docker kill | multiple | |
docker kill all containers | ||
docker kill and remove container | multiple | |
docker kill and remove all container | ||
docker remove image (with force). This includes options to remove dangling images. | multiple | |
docker remove all images (with force). This includes dangling images. | ||
docker stop and remove all & docker remove all images (with force). This includes dangling images. | ||
docker-compose up (in detached mode) | multiple | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
docker-compose up all services (in detached mode) | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
|
docker-compose build (with --no-cache and --pull) | multiple | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
docker-compose build (with --no-cache and --pull) all | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
|
docker-compose pull | multiple | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
docker-compose pull all services | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
|
docker-compose update image (rebuild or pull) | multiple | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
docker-compose build (with --no-cache and --pull) all && docker-compose pull all services | path to docker-compose file (defaults to recursive search for docker-compose.yml or docker-compose.yaml ) |
The command used to exec
into a container is dependent on the base image.
The fallback command used to exec
into a container is similar to zsh || bash || ash || sh
.
Useful standards are already implemented for images like mysql
or mongo
(PRs to add more default commands are appreciated).
You may however add custom commands that docker exec in interactive mode
will then use to exec
into a container. To do this
- Download the
.fzf-docker-exec.template
to your home directory, omitting the.template
extension:
wget -O ~/.fzfdocker-exec https://raw.githubusercontent.com/gumob/fzf-docker/main/fzf-docker-exec.template
- Customize the script as described in the file.
For more in-depth information, please check out the original project's README in the Learning by doing
section.
This project is licensed under the MIT License. The MIT License is a permissive free software license that allows for the reuse, modification, distribution, and sale of the software. It requires that the original copyright notice and license text be included in all copies or substantial portions of the software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement.