Skip to content

Instantly share code, notes, and snippets.

@ryankurte
Last active May 17, 2016 10:40
Show Gist options
  • Save ryankurte/78c7d319ebba2dd96870dfd6b068cf67 to your computer and use it in GitHub Desktop.
Save ryankurte/78c7d319ebba2dd96870dfd6b068cf67 to your computer and use it in GitHub Desktop.
Docker local environment launcher
# Example .dkrenv file
IMAGE=ryankurte/docker-arm-embedded
#!/bin/bash
# A very simple Virtualenv style wrapper to aleviate some of the complexity of using docker containers
# for project development.
# TODO: switch to named / non-temporal containers to allow additions to be made (with warnings!)
# Usage:
# Add a .dkrenv file to your project with IMAGE=image, then call dkrenv.sh from the appropriate
# directory to launch the appropriate instance.
cwd=`pwd`
config_file=$cwd/.dkrenv
config_file_secured=$cwd/.dkrenv_sec
# Check if file exists
if [ ! -f $config_file ]; then
echo "$config_file not found"
exit
fi
# Check if the file contains something we don't want
# from: http://wiki.bash-hackers.org/howto/conffile
if egrep -q -v '^#|^[^ ]*=[^;]*' "$config_file"; then
# Filter the original to a new file
egrep '^#|^[^ ]*=[^;&]*' "$config_file" > "$config_file_secured"
config_file="$config_file_secured"
fi
# Load Config
source $config_file_secured
# Check image name exists
if [ -z "$IMAGE" ]; then
echo ".dkrenv must specify IMAGE to be used"
exit
fi
# Launch instance
docker run --rm -it -v $cwd:/root $IMAGE /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment