diff --git a/Dockerfile b/Dockerfile index 4279304..80053c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,12 @@ # The Docker Image is part of Pdocker project. The image is the baseline. This image can/should be modified according to personal user. -# Version 1.0.0 +# Version 1.1.0 # Use an official debian runtime as a parent image FROM debian +# Select Working Dir +WORKDIR /home/ + # Update and upgrade Run apt-get update -y \ && apt-get upgrade -y diff --git a/README.md b/README.md index 4aaace1..b87f529 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Pdocker v1.0.0 +# Pdocker v1.1.0 Pdocker is a simple terminal UI to maintain and manage personal projects in Docker. @@ -23,7 +23,7 @@ Step 1: Clone the repo. ``` git clone https://github.com/g31s/pdocker.git ``` -Step 2: Change permissions for build.sh && pdocker.sh +Step 2: Go to project directory and change permissions for build.sh && pdocker.sh ``` chmod +x build.sh ``` @@ -40,7 +40,7 @@ pdocker * **g31s** - *Initial work* - [g31s](https://github.com/g31s) -See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project. +See also the list of [contributors](https://github.com/g31s/pdocker/contributors) who participated in this project. ## License diff --git a/build.sh b/build.sh index 959f2b0..aa62255 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ # Building the Docker Image for Pdocker project. -# Version 1.0.0 +# Version 1.1.0 echo "[*] Start Building..." # Build the image @@ -14,5 +14,5 @@ echo "alias pdocker=`pwd`/pdocker.sh" >> ~/.bashrc source ~/.bashrc -echo "[*] Image builded." +echo "[*] Image Building Complete." echo "[*] Use pdocker to start the enviroment. Enjoy." \ No newline at end of file diff --git a/pdocker.sh b/pdocker.sh index 7dd7e81..4cf5ae0 100755 --- a/pdocker.sh +++ b/pdocker.sh @@ -1,19 +1,26 @@ # The Bash script is to manage and maintain the pdocker enviroment with docker. -# Version 1.0.0 +# Version 1.1.0 # Gloabl Variables pdockercontainers=$(docker ps -a | grep pdocker | awk -F ' ' '{print ($NF ":" $1)}' | tr ',', '\n') count=$(echo $pdockercontainers | wc -w) # start_container function start the older containers base on name or id. If no container exists it creates new one. -start_container(){ - echo "[*] Type the container ID or type new to create new container." +manage_container(){ + echo "[*] Select Following Option:" + echo "=> New Container: new" + echo "=> Delete Container: delete" + echo "=> Type the Container ID to start." read -p ">>" option - if [[ $option == "new" ]]; - then + if [[ $option == "new" ]]; then echo "[*] Staring new container..." create_new_container + elif [[ $option == "delete" ]]; then + read -p "Container ID >>" container_id + docker stop $container_id + docker rm $container_id + echo "[*] Container Deleted." elif [[ $option == "exit" ]]; then exit; else @@ -26,15 +33,16 @@ start_container(){ # display_containers function display the list of existing containers in nice format. display_containers(){ echo "[*] List of containers ids. Newer are first." - echo "===============================" - echo " ID Name" + echo "=======================" + echo " ID Name" + echo "------------ --------" for containerid in $pdockercontainers do echo $containerid | awk -F ':' '{print ($NF "\t" $1)}' done - echo "===============================" + echo "=======================" } # more_than_one function display nice error message if there are more than 1 existing containers @@ -48,8 +56,7 @@ get_name(){ while true do read -p "[*] New Container Name:" name - if [[ $name =~ ^.[a-z]* ]] - then + if [[ $name =~ ^.[a-z]* ]]; then break; else echo "[-] Invalid Input. Try again." @@ -57,21 +64,36 @@ get_name(){ done } +# get_volume function ask user for adding volumne to container +get_volume(){ + echo "[*] Select Options for adding Volume:" + echo "=> Select current: y" + echo "=> No volume: n" + echo "=> Type the path for volume" + + read -p ">>" volumepath + + if [[ $volumepath == "y" ]]; then + volume="--volume $(pwd):/home/$name" + elif [[ $volumepath != "n" ]]; then + volume="--volume $volumepath:/home/$name" + fi +} + # create_new_container creates new docker container create_new_container(){ get_name - docker run --name $name -t -i pdocker /bin/bash + get_volume + docker run --name $name $volume -t -i pdocker /bin/bash } # check_containers check if there is existing containers. check_containers(){ - # - if [ $count -eq 0 ] - then + if [ $count -eq 0 ]; then create_new_container else more_than_one - start_container + manage_container fi }