-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gurjant Singh
authored and
Gurjant Singh
committed
Jul 12, 2019
0 parents
commit b702fa5
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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 | ||
|
||
# Use an official debian runtime as a parent image | ||
FROM debian | ||
|
||
# Update and upgrade | ||
Run apt-get update -y \ | ||
&& apt-get upgrade -y | ||
|
||
|
||
# Install Python | ||
Run apt-get install python -y | ||
|
||
# Install Ruby | ||
Run apt-get install ruby -y | ||
|
||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Pdocker v1.0.0 | ||
|
||
Pdocker is a simple terminal UI to maintain and manage personal projects in Docker. | ||
|
||
## Getting Started | ||
|
||
These instructions will get you a copy of the project up and running on your local machine. | ||
|
||
### Operation Systems | ||
|
||
* Mac OS | ||
|
||
### Prerequisites | ||
|
||
* Docker | ||
* Bash | ||
|
||
### Installing | ||
|
||
A step by step series of examples that tell you how to get a pdocker running | ||
|
||
Step 1: Clone the repo. | ||
``` | ||
git clone https://github.com/g31s/pdocker.git | ||
``` | ||
Step 2: Change permissions for build.sh && pdocker.sh | ||
``` | ||
chmod +x build.sh | ||
``` | ||
Step 3: Run build.sh | ||
``` | ||
./build.sh | ||
``` | ||
Step 4: Type pdocker in terminal | ||
``` | ||
pdocker | ||
``` | ||
|
||
## Authors | ||
|
||
* **g13s** - *Initial work* - [g31s](https://github.com/g31s) | ||
|
||
See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Building the Docker Image for Pdocker project. | ||
# Version 1.0.0 | ||
|
||
echo "[*] Start Building..." | ||
# Build the image | ||
sudo docker build \ | ||
--rm \ | ||
-t pdocker . | ||
|
||
# Add the alias to bashrc | ||
echo "# Pdocker alias" >> ~/.bashrc | ||
# Add -v ~/hostpath/Projects:/Projects to share volume | ||
echo "alias pdocker=`pwd`/pdocker.sh" >> ~/.bashrc | ||
|
||
source ~/.bashrc | ||
|
||
echo "[*] Image builded." | ||
echo "[*] Use pdocker to start the enviroment. Enjoy." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# The Bash script is to manage and maintain the pdocker enviroment with docker. | ||
# Version 1.0.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." | ||
read -p ">>" option | ||
|
||
if [[ $option == "new" ]]; | ||
then | ||
echo "[*] Staring new container..." | ||
create_new_container | ||
elif [[ $option == "exit" ]]; then | ||
exit; | ||
else | ||
echo "[*] Staring $option container..." | ||
docker start $option | ||
docker exec -it $option /bin/bash | ||
fi | ||
} | ||
|
||
# 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" | ||
|
||
for containerid in $pdockercontainers | ||
do | ||
echo $containerid | awk -F ':' '{print ($NF "\t" $1)}' | ||
done | ||
|
||
echo "===============================" | ||
} | ||
|
||
# more_than_one function display nice error message if there are more than 1 existing containers | ||
more_than_one(){ | ||
echo "[!] Pdocker containers already exists." | ||
display_containers | ||
} | ||
|
||
# get_name funciton ask user for the name for the container. | ||
get_name(){ | ||
while true | ||
do | ||
read -p "[*] New Container Name:" name | ||
if [[ $name =~ ^.[a-z]* ]] | ||
then | ||
break; | ||
else | ||
echo "[-] Invalid Input. Try again." | ||
fi | ||
done | ||
} | ||
|
||
# create_new_container creates new docker container | ||
create_new_container(){ | ||
get_name | ||
docker run --name $name -t -i pdocker /bin/bash | ||
} | ||
|
||
# check_containers check if there is existing containers. | ||
check_containers(){ | ||
# | ||
if [ $count -eq 0 ] | ||
then | ||
create_new_container | ||
else | ||
more_than_one | ||
start_container | ||
fi | ||
} | ||
|
||
main(){ | ||
# Check if container already exists | ||
check_containers | ||
echo "[*] Bye." | ||
} | ||
|
||
# Everything starts here. | ||
main |