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

101 lines
2 KiB
Bash
Raw Normal View History

2023-12-07 04:02:47 +03:00
# Show container's volumes.
# Usage: docker_volumes <CONTAINER>
2023-12-07 01:44:42 +03:00
function docker_volumes() {
2023-12-07 00:42:06 +03:00
docker inspect -f '{{ .Mounts }}' "${@}"
}
2023-08-08 16:24:15 +03:00
2023-12-07 00:42:06 +03:00
# Check if any container exited.
2023-12-07 01:44:42 +03:00
function docker_health() {
2023-12-07 00:42:06 +03:00
docker ps -a | grep Exited
}
2023-08-08 16:24:15 +03:00
2023-12-07 05:02:12 +03:00
# Find out container's IP address.
# Usage: docker_ip <CONTAINER>
function docker_ip() {
docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' "${1}" | sed "s/^.//" | sed "s/.$//"
}
# Update all docker images.
function docker_update() {
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
}
2023-12-07 04:02:47 +03:00
# Prune everything.
2023-12-07 01:44:42 +03:00
function docker_prune() {
2023-12-07 00:42:06 +03:00
docker system prune --volumes --all
}
# Docker compose shortcut.
2023-12-07 01:44:42 +03:00
function dc() {
2023-12-07 00:42:06 +03:00
docker compose "${@}"
}
# Docker compose up.
2023-12-07 04:02:47 +03:00
# Usage: dcu [SERVICES]
2023-12-07 01:44:42 +03:00
function dcu() {
2023-12-07 00:42:06 +03:00
docker compose up -d "${@}"
}
# Docker compose down.
2023-12-07 04:02:47 +03:00
# Usage: dcd [SERVICES]
2023-12-07 01:44:42 +03:00
function dcd() {
2023-12-07 00:42:06 +03:00
docker compose down "${@}"
}
# Docker compose pull.
2023-12-07 04:02:47 +03:00
# Usage: dcp [SERVICES]
2023-12-07 01:44:42 +03:00
function dcp() {
2023-12-07 00:42:06 +03:00
docker compose pull "${@}"
}
# Docker compose logs.
2023-12-07 04:02:47 +03:00
# Usage: dcl [SERVICES]
2023-12-07 01:44:42 +03:00
function dcl() {
2023-12-07 00:42:06 +03:00
docker compose logs -f "${@}"
}
# Docker compose restart.
2023-12-07 04:02:47 +03:00
# Usage: dcr [SERVICES]
2023-12-07 01:44:42 +03:00
function dcr() {
2023-12-07 00:42:06 +03:00
docker compose restart "${@}"
}
# Docker compose stop.
2023-12-07 04:02:47 +03:00
# Usage: dcs [SERVICES]
2023-12-07 01:44:42 +03:00
function dcs() {
2023-12-07 00:42:06 +03:00
docker compose stop "${@}"
}
# Docker compose down & up specified services.
# Usage: dcdu [SERVICES]
2023-12-07 01:44:42 +03:00
function dcdu() {
2023-12-05 21:50:45 +03:00
dcd "${@}"
dcu "${@}"
2023-10-23 03:31:00 +03:00
}
2023-12-07 00:42:06 +03:00
# Docker compose pull & up specified services.
# Usage: dcpu [SERVICES]
2023-12-07 01:44:42 +03:00
function dcpu() {
2023-12-05 21:50:45 +03:00
dcp "${@}"
dcu "${@}"
2023-10-23 03:31:00 +03:00
}
2023-12-07 00:42:06 +03:00
# Docker compose up & attach to logs for specified services.
# Usage: dcul [SERVICES]
2023-12-07 01:44:42 +03:00
function dcul() {
2023-12-05 21:50:45 +03:00
dcu "${@}" && dcl "${@}"
2023-10-23 03:31:00 +03:00
}
2023-08-08 16:24:15 +03:00
2023-12-07 04:02:47 +03:00
# Autocomplete with available services.
2023-12-07 01:44:42 +03:00
function _dc_services() {
2023-12-05 21:50:45 +03:00
_autocomplete "$(docker compose config --services 2> /dev/null)"
2023-10-23 03:31:00 +03:00
}
2023-12-07 04:02:47 +03:00
# Autocomplete with available container names.
2023-12-07 01:44:42 +03:00
function _dc_containers() {
2023-12-05 21:50:45 +03:00
_autocomplete "$(docker ps --format "\""{{.Names}}"\"")"
2023-10-23 03:31:00 +03:00
}
complete -F _dc_services dcu dcd dcp dcl dcul dcdu dcr dcs dcpu
complete -F _dc_containers docker_volumes docker_ip