Skip to content

Instantly share code, notes, and snippets.

@Kline-
Created June 25, 2024 22:07
Show Gist options
  • Save Kline-/9c74c4acb12a012f16e75cc8a49a1329 to your computer and use it in GitHub Desktop.
Save Kline-/9c74c4acb12a012f16e75cc8a49a1329 to your computer and use it in GitHub Desktop.
A wrapper for running arbitrary Python scripts inside a docker container.
#!/bin/bash
#Need to attach to a docker network for pip to function
NET=docker_bridge
if [[ -f "requirements.txt" ]]; then
docker run --network $NET -it --rm -v "$PWD":/usr/src/app -w /usr/src/app python:3 sh -c "python -m pip --disable-pip-version-check -qqq install -r requirements.txt ; python $*"
else
docker run --network $NET -it --rm -v "$PWD":/usr/src/app -w /usr/src/app python:3 python $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment