This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/docker.sh

69 lines
1.4 KiB
Bash
Raw Normal View History

2023-08-08 16:24:15 +03:00
# show container's volumes.
alias docker_volumes="docker inspect -f '{{ .Mounts }}'"
# check if container exited.
alias docker_health="docker ps -a | grep Exited"
# prune everything.
alias docker_prune="docker system prune --volumes --all"
# short aliases.
2023-10-30 03:49:10 +03:00
# usage: dc [SERVICE]
2023-08-08 16:24:15 +03:00
alias dc="docker compose"
alias dcu="docker compose up -d"
alias dcd="docker compose down"
alias dcp="docker compose pull"
alias dcl="docker compose logs -f"
alias dcr="docker compose restart"
alias dcs="docker compose stop"
2023-10-23 03:31:00 +03:00
2023-10-30 03:49:10 +03:00
# down & up specified services.
# usage: dcdu [SERVICES]
2023-10-23 03:31:00 +03:00
dcdu()
{
dcd "${@}"
dcu "${@}"
}
2023-10-30 03:49:10 +03:00
# pull & up specified services.
# usage: dcpu [SERVICES]
2023-10-23 03:31:00 +03:00
dcpu()
{
dcp "${@}"
dcu "${@}"
}
2023-10-30 03:49:10 +03:00
# up & attach to logs for specified services.
# usage: dcul [SERVICES]
2023-10-23 03:31:00 +03:00
dcul()
{
dcu "${@}" && dcl "${@}"
}
2023-08-08 16:24:15 +03:00
# find out container's IP address.
2023-10-30 03:49:10 +03:00
# usage: docker_up <CONTAINER NAME>
2023-08-08 16:24:15 +03:00
docker_ip()
{
docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' $1 | sed "s/^.//" | sed "s/.$//"
}
# update all docker images.
docker_update()
{
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
}
2023-10-23 03:31:00 +03:00
# autocomplete.
_dc_services()
{
_autocomplete "$(docker compose config --services 2> /dev/null)"
}
_dc_containers()
{
_autocomplete "$(docker ps --format "\""{{.Names}}"\"")"
}
complete -F _dc_services dcu dcd dcp dcl dcul dcdu dcr dcs dcpu
complete -F _dc_containers docker_volumes docker_ip