Last active
June 9, 2023 19:55
-
-
Save cange/77222ffc563639f5487747c73bcf8a51 to your computer and use it in GitHub Desktop.
Convinients aliases for docker and docker compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Points to the global docker-compose config | |
local _compose_file="$HOME/workspace/services/docker-compose/docker-compose.yml" | |
# https://docs.docker.com/compose/reference/envvars/ | |
if [[ -n "$COMPOSE_FILE" ]]; then | |
export COMPOSE_FILE="${COMPOSE_FILE}${COMPOSE_PATH_SEPARATOR:-":"}${_compose_file}" | |
else | |
export COMPOSE_FILE=$_compose_file | |
fi | |
# ensure docker is running on arm64 (macos M1+) | |
# https://docs.docker.com/engine/reference/commandline/cli/#environment-variables | |
export DOCKER_DEFAULT_PLATFORM=linux/amd64 | |
# allows to call docker-compose from within the services folder without | |
# specifying the service name | |
function _docker_compose() { | |
local cmd=$1 | |
local dirname=$(basename $(pwd)) | |
shift 1 | |
docker-compose "$cmd" $dirname "$@" | |
} | |
# aliases | |
alias dco="_docker_compose " # Docker-compose main command | |
alias dce="dco exec" # Execute command inside a container | |
alias dcdn="dco down" # Stop and remove container | |
alias dcrb="dco up --detach --build --force-recreate" # Rebuild | |
alias dcbl="dco exec bundle" # Execute Rails bundle command | |
alias dcy="dco exec yarn" # Execute yarn command | |
alias dcrs="dco restart" # Restart container | |
alias dcup="dco up --detach" # Start container and its dependencies | |
alias dcl="dco logs --follow --tail=100" # Show container logs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment