Menu

Christian Stryczynski

Freelance software developer. Haskelling at night. Hopefully unconventional. Fan of Dvorak

Docker command line functions that will change your life

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: https://github.com/chrissound/LinuxVerboseCommandLib

Written by Christian Stryczynski on Tuesday July 18, 2017

Permalink -

« Log exceptions and errors with PHP Slim 3 using Monolog - The Ultimate PHP Docker Compose Configuration »