Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My basic "build docker image from any directory" script. I have retyped this basic build script so many times that I basically didn't need to create this gist. Until I go a few weeks without doing Docker.
#!/bin/bash -eux
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$script_dir"
docker build -t $(basename $PWD) .
#!/bin/bash -eux
# Put common options here
docker_run_options="--volume $PWD/.npm:/root/.npm -p 8000:8000 --memory 4096m"
# Use env var DOCKER_RUN_OPTIONS to overwrite ^^them^^ at invocation time
docker_run_options="${DOCKER_RUN_OPTIONS:-$docker_run_options}"
readonly script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly image_name="$(basename $script_dir)"
# Generic run command
docker run -it --rm --name rtg --workdir /usr/src/app --volume $PWD:/usr/src/app $docker_run_options $image_name bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.