Skip to content

Commit

Permalink
In v1.1.0 container delete, include volume functionality added and so…
Browse files Browse the repository at this point in the history
…me minor fixes.
  • Loading branch information
Gurjant Singh authored and Gurjant Singh committed Jul 13, 2019
1 parent 8ed5ef3 commit 3aa6336
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
```
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."
52 changes: 37 additions & 15 deletions pdocker.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -48,30 +56,44 @@ 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."
fi
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
}

Expand Down

0 comments on commit 3aa6336

Please sign in to comment.