Skip to content

Commit

Permalink
Merge pull request #3 from CMIPT/develop
Browse files Browse the repository at this point in the history
Fix a bug and add a new option.
  • Loading branch information
Kaiser-Yang authored May 17, 2024
2 parents 9878ce3 + 3ec6b2a commit 5e22ea2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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 \\
Expand All @@ -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
Expand Down
25 changes: 19 additions & 6 deletions create_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \\
Expand Down Expand Up @@ -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
Expand All @@ -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;;
Expand All @@ -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;;
Expand Down Expand Up @@ -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

0 comments on commit 5e22ea2

Please sign in to comment.