Skip to content

Instantly share code, notes, and snippets.

@hoto17296
Created August 1, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoto17296/b563f9b5b2f41957c5640c79c030c8db to your computer and use it in GitHub Desktop.
Save hoto17296/b563f9b5b2f41957c5640c79c030c8db to your computer and use it in GitHub Desktop.
Docker イメージ内の TensorBoard を操作するスクリプト
#!/bin/bash -u
image_name=docker_image_name
tb_container_name=tensorboard
port=6006
app_root=$(cd $(dirname $0)/..; pwd)
show_help() {
echo "Usage: bin/tensorboard (start|stop|restart|status)"
}
check_status() {
docker ps --format '{{.Names}}' | grep "^${tb_container_name}$" >/dev/null
}
start_container() {
if check_status; then
echo 'TensorBoard is already running.'
return
fi
echo 'Starting...'
container_command="tensorboard --logdir=/app/logs $@"
nvidia-docker run --rm -d -v ${app_root}:/app -p ${port}:6006 --name ${tb_container_name} ${image_name} ${container_command} >/dev/null
echo "TensorBoard is running on port ${port}."
}
stop_container() {
if ! check_status; then
echo 'TensorBoard is not running.'
return
fi
echo 'Stopping...'
docker stop ${tb_container_name} >/dev/null
echo 'TensorBoard is stopped.'
}
if [ $# -ne 1 ]; then
show_help
exit 1
fi
subcommand="$1"
shift
case $subcommand in
start)
start_container
;;
stop)
stop_container
;;
restart)
stop_container
start_container
;;
status)
if check_status
then echo 'TensorBoard is running.'
else echo 'TensorBoard is not running.'
fi
;;
*)
show_help
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment