From 3ec6b2a2d5478c05ae7fba8aa9120bfb6c4bd180 Mon Sep 17 00:00:00 2001 From: Kaiser-Yang <624626089@qq.com> Date: Fri, 17 May 2024 20:48:18 +0800 Subject: [PATCH] Fix a bug and add a new option We find that `-v` can not work when creating a new docker, because we forget to add `--volume` before the parameter, then we fix this. And we add a new option to control wheter or not to restart the docker every time the physical machine restarts. --- README.md | 24 +++++++++++------------- create_docker.sh | 25 +++++++++++++++++++------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index db508b6..16a98c0 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,13 @@ * Finish basic functionalities of scripts. * Finish README.md of English version. -## Release-v0.1.0 +## Release-v0.1.1 * Fix some typos +## Release-v0.1.2 +* Fix a bug: `-v` can not work +* Add an option that can control whether or not to restart the new docker when physical machine restarts + # docker-script Some scripts for creating and configuring dockers. @@ -71,14 +75,17 @@ Options: : more than one file, you need put all the files into a directory, then use : '-f dir' to copy the whole directory. - -a, --auto-install: whether or not to install automatically, the default value is 1. When + -a, --auto-install: whether or not to install automatically, the default value is 1. When : enabled, this will install some basic tools rather than just enter the : new docker. - --password: whether or not to add a password for the root user, the default value is + --password: whether or not to add a password for the root user, the default value is : 1. When enabled, this will add password for the root user until success. - -h, --help: print the manual page. + --auto-restart: whether or not to restart the docker when physical machine restarts. The +: default value is 1, you can use --auto-restart 0 to disable this. + + -h, --help: print the manual page. Example: $0 --name newdocker --publish 7777:22 --with-gpu 1 --gpus all -e \\ @@ -87,15 +94,6 @@ Example: $0 -n newdocker -p 7777:22 $0 --name newdocker --publish 7777:22 --with-gpu 0 --distro ubuntu:latest --file \\ - ./docker_initializer - - $0 -n newdocker -p 7777:22 -w 0 - -Note: - The second example will acts same as the first one does. - The fourth example will acts same as the third one does. - If you want to pass more than one argument for the same option, you should use more than one - (e.g., -p 22:22 -p 33:33). ``` # Something for Docker Users diff --git a/create_docker.sh b/create_docker.sh index 206f4eb..291baf0 100644 --- a/create_docker.sh +++ b/create_docker.sh @@ -27,18 +27,21 @@ Options: -f, --file: a file or a directory will be copied into the new docker. The default : value is './docker_initializer'. If you don't want to copy files into the -: docker, you can input 'n' when confirming the command. If you want copy +: docker, you can input 'n' when confirming the command. If you want to copy : more than one file, you need put all the files into a directory, then use : '-f dir' to copy the whole directory. - -a, --auto-install: whether or not to install automatically, the default value is 1. When + -a, --auto-install: whether or not to install automatically, the default value is 1. When : enabled, this will install some basic tools rather than just enter the : new docker. - --password: whether or not to add a password for the root user, the default value is + --password: whether or not to add a password for the root user, the default value is : 1. When enabled, this will add password for the root user until success. - -h, --help: print the manual page. + --auto-restart: whether or not to restart the docker when physical machine restarts. The +: default value is 1, you can use --auto-restart 0 to disable this. + + -h, --help: print the manual page. Example: $0 --name newdocker --publish 7777:22 --with-gpu 1 --gpus all -e \\ @@ -66,7 +69,7 @@ usage() { # Make sure the parameters after -l and -o are at the smae line, even it is too long if ! options=$(getopt \ -o n:p:Pw:g:e:d:v:f:a:h \ - -l name:,publish:,publish-all,with-gpu:,gpus:,env:,distro:,volume:,file:,auto-install:,password:,help \ + -l name:,publish:,publish-all,with-gpu:,gpus:,env:,distro:,volume:,file:,auto-install:,password:,auto-restart:,help \ -n "$(basename "$0")" -- "$@"); then usage 1 fi @@ -80,6 +83,7 @@ envs=() volume=() autoinstall=1 password=1 +autorestart=1 while true ; do case "$1" in -n|--name) name+=("--name $2"); pure_name=$2; shift 2;; @@ -89,10 +93,11 @@ while true ; do -g|--gpus) gpus+=("--gpus $2"); shift 2;; -e|--env) envs+=("--env $2"); shift 2;; -d|--distro) distro="$2"; shift 2;; - -v|--volume) volume+=("$2"); shift 2;; + -v|--volume) volume+=("--volume $2"); shift 2;; -f|--file) file_or_dir="$2"; shift 2;; -a|--auto-install) autoinstall="$2"; shift 2;; --password) password="$2"; shift 2;; + --auto-restart) autorestart="$2"; shift 2;; -h|--help) usage 0;; --) shift; break;; *) usage 1;; @@ -198,5 +203,13 @@ if ! confirm_cmd "$docker_enter_cmd"; then exit 1 fi +autorestart_cmd="docker update --restart=always $pure_name" +if [ "$autorestart" -eq 1 ]; then + if ! confirm_cmd "$autorestart_cmd"; then + echo "terminated" + exit 1 + fi +fi + exit 0