Last active
June 15, 2021 03:06
-
-
Save devymex/96cba35cdc831b7f89b6a88357d59471 to your computer and use it in GitHub Desktop.
Run an docker image as a container with public ssh port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
if [ $# -eq 0 ]; then | |
echo "Please specify an name for the new container!" | |
exit | |
fi | |
indices="" | |
for cid in $(docker container ls -a | sed 1,1d | awk '{print $1}'); do | |
port=$(docker inspect --format='{{if .NetworkSettings.Ports}}{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}{{else}}{{"null"}}{{end}}' $cid) | |
indices=$indices" "$port | |
done | |
available_port="" | |
for i in {3003..3099}; do | |
if [ -z $(echo $indices | grep -o "$i") ]; then | |
available_port=$i | |
break | |
fi | |
done | |
docker run -it -d --name $1 -p $available_port:22 --gpus all -v /mnt/data:/data --shm-size=1G nvidia/cuda:devbase /bin/init | |
echo "Listening port "$available_port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment