Skip to content

Instantly share code, notes, and snippets.

@maximivanov
Last active January 15, 2021 12:50
Show Gist options
  • Save maximivanov/2bc950e15b21aa8ccf692cfabc2fb551 to your computer and use it in GitHub Desktop.
Save maximivanov/2bc950e15b21aa8ccf692cfabc2fb551 to your computer and use it in GitHub Desktop.
Shell script shortcut to start a local dev container
#!/bin/bash
#
# Shortcut script to start Docker dev container in the current directory
#
# chmod+x ddev.sh
# ln -s ddev.sh /usr/local/bin/ddev
#
# Usage: ddev [-p port mapping] [-n container name]
# ddev -p 8080:8080 -n my-node-project
# ddev # container name defaults to the current directory
while getopts ":n:p:" opt; do
case $opt in
n) name="$OPTARG"
;;
p) port="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
optional_params=()
[[ ! -z "$port" ]] && optional_params+=(-p "$port")
[[ -z "$name" ]] && name=${PWD##*/}
exec docker run \
-it \
--rm \
-v /Users/maxivanov/.p10k.docker.zsh:/root/.p10k.zsh:ro \
-v $(pwd):/var/app \
-e DOCKER_CONTAINER_NAME="$name" \
"${optional_params[@]}" \
--name "$name" \
maxivanov/node-dev-img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment