Chris Stryczynski

Software Developer / Consultant

Useful docker command line functions


You'll need FZF installed for some of these commands.

# Stop all running docker containers
stopAllDockerContainers() { sudo docker stop `sudo docker ps -q`}
# Delete current docker-compose volumes
deleteDockerComposeVolumes() { sudo docker-compose down -v }
showLatestCreatedDockerContainer() { sudo docker ps -a --latest}
getLatestCreatedDockerContainerId() { sudo docker ps -a --latest -q}
startLatestCreatedDockerContainer() { sudo docker start `sudo docker ps -a --latest -q`}
listDockerContainers() { sudo docker ps -a }
listRunningDockerContainers() { sudo docker ps}
# List the docker containers by name and their IP
listRunningDockerContainerIps() { sudo docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(sudo docker ps -q) }
# Enter the bash prompt within a docker container (will prompt you with a selection of currently running containers)
enterDockerContainerBash() { sudo docker exec -it $(sudo docker ps --format "{{.Names}}" | fzf | cat) /bin/bash }
runCommandInDockerContainer() { sudo docker exec -it "$@"}
runCommandInDockerContainerWithContainerPrompt() { sudo docker exec -it $(promptForRunningDockerContainer) "$@"}
promptForRunningDockerContainer() { echo $(sudo docker ps --format "{{.Names}}" | fzf) }

All of these commands (and more) are available in the following project: