Last active
January 15, 2021 12:50
-
-
Save maximivanov/2bc950e15b21aa8ccf692cfabc2fb551 to your computer and use it in GitHub Desktop.
Shell script shortcut to start a local dev container
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
#!/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