Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created March 30, 2020 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyckahn/91d9edb7fb7a0f81fed573c229d335a8 to your computer and use it in GitHub Desktop.
Save jeremyckahn/91d9edb7fb7a0f81fed573c229d335a8 to your computer and use it in GitHub Desktop.
Run a shell script in a Docker environment
docker run \
# Set the current host working directory as the container's /tmp so the container can access it
-v $(pwd):/tmp \
# Mount your home directory as the Docker root user's home directory to inherit any host dotfiles
-v $HOME:/root \
# (Effectively) set the host's working directory as the container's working directory
-w /tmp \
# Set any environment variables you need (feel free to add as many as you need, each with a new --env switch)
--env ENV_VAR=$ENV_VAR \
# Select whatever image makes the most sense for you here
-i node:latest \
# Run your script
/bin/bash -c path/to/script.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment