Skip to content

Instantly share code, notes, and snippets.

@eschen42
Last active September 9, 2017 15:06
Show Gist options
  • Save eschen42/249dc9e205ceafee85b94f248320a7ad to your computer and use it in GitHub Desktop.
Save eschen42/249dc9e205ceafee85b94f248320a7ad to your computer and use it in GitHub Desktop.
Run bash in a new or existing container
#!/bin/sh
# Run bash within an already-running container
# arg1 - ID or nickname of a running container
if [ "'${COLUMNS}x'" = "'x'" ]; then
echo Please 'export COLUMNS' before running this script.
else
sudo docker exec -ti $1 bash -c "export TERM=xterm; export COLUMNS=$COLUMNS; /bin/bash"
fi
#!/bin/sh
# Run a container and remove the volume when it exits
# arg1 - name or name:tag of an image
if [ "'${COLUMNS}x'" = "'x'" ]; then
echo Please 'export COLUMNS' before running this script.
else
sudo docker run --rm -ti $1 bash -c "export TERM=xterm; export COLUMNS=$COLUMNS; /bin/bash"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment