Docker3asy - docker made easy

Docker3asy - docker made easy

This is a write-up of my project on container technology completely focused on docker and one of it's best use case. I have named it as Docker3asy as docker made easy, because you don't require any knowledge of docker or docker-compose, you just need to know how to run a python program and it will set up a complete new wordpress and nextcloud server having individual mysql database additionally it will provide two Operating System running parallel. First Kali-Linux, so it can be utilized in workshop, training or as personal Hacking Lab even educational platform can use it for providing fast and effective lab, so hackers enjoy this platform without worrying about installation of bulky OS or VM. Second Ubuntu 14.04, this also have all possible use case as mentioned above. Coders and Linux newbies use this for practicing without worrying about installation of bulky OS or VM. This whole bundle can be launched within 2 second for first otherwise less then a second in just a click. ???

No alt text provided for this image


Why to use docker3asy?

Well it's launched on a container ship technology called docker so it is very fast and efficient. You don't require any knowledge to use this because you just have to run a basic command to run a python script, this will do all the required things for you. It gives solution to many use cases like:

  1. Create your own educational blogging website or any website with necessary operating system available in parallel.
  2. Create your own cloud service integrated with your educational website to save space of your host machine.
  3. Most important this all happens in just seconds. If by chance your server goes down you can keep it up just by one click and even load balancing is very simple for the user.(It can be done with just tweaking a part) You can make this whole thing automated with kubernetes, openshift and jenkins (Trust me there's nothing complex in this world you can learn it in few days, refer my previous article for knowing the same) but this won't bother by using this.

How to use docker3asy?

This is a YouTube video of how to run this simple python script which will do everything for you. For me the version of python is v3 hence i am using command of python3 for you if the version is different don't worry just run python script.py, this will do your work.

Basic requirement:

  1. Install docker on your machine where you're running this code.
  2. Install docker-compose on your machine where you're running this code.

GitHub Link for the two files: https://bit.ly/3aT96at

How to make your own docker3asy?

No alt text provided for this image

First let's see how to do it manually. To do this first of all you need some images, that i have listed below.

  1. wordpress:5.1.1-php7.3-apache: Command to install: docker pull wordpress:5.1.1-php7.3-apache
  2. mysql:5.7: Command to install: docker pull mysql:5.7
  3. shubhambhalala/kali-nmap-metasploit-shellinabox: Command to install: docker pull shubhambhalala/kali-nmap-metasploit-shellinabox:latest
  4. shubhambhalala/ubuntu14.04-shellinabox: Command to install: docker pull shubhambhalala/ubuntu14.04-shellinabox:latest
  5. nextcloud:16.0.10-apache: Command to install: docker pull nextcloud:16.0.10-apache

We have to download this because we are doing it manually if you use the docker-compose.yml file or script.py it'll automatically download it from docker hub, where i have uploaded no.3 and no.4 image as mentioned above others are by default available.

Then you have to run following commands to set up the desired environment.

  1. docker container run -dit -p 8083:80 --name kalios shubhambhalala/kali-nmap-metasploit-shellinabox what this command will do is, first it'll run the image file in detached mode i.e. in background with interactive terminal mode docker container run -dit (detached,interactive,terminal) and expose the port 80 of container with port 8083 of your host machine where you're running it -p 8083:80. This concept is called PATing(Port Address Translation). Now you can access shellinabox of the image through your web-browser at https://localhost:8083 it may ask certificate verification, do agree to that and add it as an exception because it uses openssl and ssh in backend to provide shell. By default ID:PASSWORD is root:toor.
  2. docker container run -dit -p 8084:80 --name ubuntuos shubhambhalala/ubuntu14.04-shellinabox what this command will do is, first it'll run the image file in detached mode i.e. in background with interactive terminal mode docker container run -dit (detached,interactive,terminal) and expose the port 80 of container with port 8084 of your host machine where you're running it -p 8084:80. This concept is called PATing(Port Address Translation). Now you can access shellinabox of the image through your web-browser at https://localhost:8084 it may ask certificate verification, do agree to that and add it as an exception because it uses openssl and ssh in backend to provide shell. By default ID:PASSWORD is root1:toor.
  3. docker volume create wpsql_storage && docker volume create wp_storage this will create two volumes or say separate hard-disk one for mysql server other for wordpress. Similarly create for nextcloud with different name. docker volume create ncsql_storage && docker volume create nc_storage.
  4. docker container run -d -e MYSQL_ROOT_PASSWORD=<give your machine password> -e MYSQL_USER=<username for database> -e MYSQL_PASSWORD=<password for the user> -e MYSQL_DATABASE=<database name you want to give> -v wpsql_storage:/var/lib/mysql --name wpsqlos mysql:5.7 what this command will do is, set environment variables for the container to be created using -e then mount the created hard-disk or volume using -v to the mount point given after : . You can get the information of what environment variables to pass in it's documentation available in docker hub.
  5. Similarly you have to do for nextcloud also by changing the name and creating new volumes. docker container run -d -e MYSQL_ROOT_PASSWORD=<give your machine password> -e MYSQL_USER=<username for database> -e MYSQL_PASSWORD=<password for the user> -e MYSQL_DATABASE=<database name you want to give> -v ncsql_storage:/var/lib/mysql --name ncsqlos mysql:5.7 what this command will do is, set environment variables for the container to be created using -e then mount the created hard-disk or volume using -v to the mount point given after : . You can get the information of what environment variables to pass in it's documentation available in docker hub.
  6. Now we have to launch two more container and link it with this two created server. docker container -dit -e WORDPRESS_DB_NAME=wpsqlos -e WORDPRESS_DB_USER=<username you gave before> -e WORDPRESS_DB_PASSWORD=<password of the user> -e WORDPRESS_DB_NAME=<name of the database created> -v wp_storage:/var/www/html --link wpsqlos -p 8081:80 --name wpos wordpress:5.1.1-php7.3-apache what this command does is pass the environment variable at entrypoint or say at the time of creating container informing where you have to connect to database in this case it's mysql:5.7 and expose it on port 8081 of your host machine where you are running this. This will even link with the server using --link . Similarly we have to do it for nextcloud. To know the entrypoint either we can go to docker hub or inspect the container or see the history of the image and check whether it requires any environment variable or not. docker container inspect <container name or image name> and docker history <image name> .
  7. docker container run -dit -e MYSQL_HOST=ncsqlos -e MYSQL_USER=<username given before> -e MYSQL_PASSWORD=<password for the user> -e MYSQL_DATABASE=<database name you given before> -v nc_storage:/ var/www/html --link ncsqlos -p 8082:80 --name ncos nextcloud:16.0.10-apache nextcloud has some different name for environment variable.
  8. After this your environment is ready to use go to your browser and access everything on https://localhost:8081 - wordpress https://localhost:8082 - nextcloud https://localhost:8083 - kali-linux https://localhost:8084 - ubuntu14.04

This is all about manual creation. But how to create it and maintain it as Infrastructure as a Code(IaaS). It's using docker-compose, it uses YAML format file to make it an easy and manageable source code file to easily share and create environment which we created manually. For this you have to create a file with name docker-compose.yml, for now assume we have to give this name only but it's not always the case you can give other name or make multiple files also, for that we need to change the options of docker-compose command.

To see the file visit my GitHub account and check it out.

There you will see some keywords which i will be explaining you.

  1. version: "3" - This is to mention docker-compose command that we are using the latest version of docker compose. Without which it won't be able to run.
  2. services: - This tells the docker compose that what so ever i am having inside this is need to be created as service. Here all the container created are recognized as service.
  3. First file inside service is the container name you have to give. Then there is image: - This tells docker compose that use this image with specific version number to run, if you don't have the image it'll first download it and then run it.
  4. volumes: - This tells which volume to be mounted and where. Here we put '-' hyphen because one container might have multiple volume so '-' represents list here. In YAML everything is a key:value pair hence its used with ':" and to specify list of items we use "-", here also we have to keep in ind the indentation.
  5. restart: - This keyword is used to specify that we can restart the same container depending upon the value we give, here we gave always.
  6. environment: - This is the environment variable that we pass using -e, here we use ":" instead of "=".
  7. depends_on: - This is what we do as "--link".
  8. ports: - To do PATing which we do using "-p".
  9. volumes: - At the end you can see another section of volumes, what does this represents is, docker compose have to create these volumes before running services if they are not by defalut made.

Now you are good to go for building or setting-up your environment with just one command that is docker-compose up . This will create whole environment which you can browse. I would suggest you all to see my YouTube video that i posted earlier in this article or the screenshots attached here below to visualize things.

The python script which i created is just running the docker-compose up command using os module in python and launching the two OS by running the general docker command. In brief, import os loads the os module of python using which you can run CLI(Command Line Interface) commands. So for this i have used system() function of os module os.system("<command you want to perform>").

This project was build in a day. So you can think how much powerful this tool is it's developed by Solomon Hykes. I really thank my trainer and mentor Vimal Daga sir to give this training for free under his campaign IIEC.

Screenshot for reference:

No container is running right now. I'll run my script.py
wordpress launched
nextcloud launched
kali linux launched
ubuntu launched
now these containers are running
docker-compose.yml
docker-compose.yml
script.py


Ashish Gupta

Engineer at ZF Group | Power Platform Developer Associate | 5 × Microsoft Certified

4 年

Nyc work!!

回复
Abhishek Chouhan

DevOps Engineer at Toorak Capital

4 年

nice project buddy!

Shubham Bhalala

Data Scientist @System2 | MS Data Science @Columbia University | Data Science, MLOps Engineer

4 年
回复
Shubham Bhalala

Data Scientist @System2 | MS Data Science @Columbia University | Data Science, MLOps Engineer

4 年

Thank you Vimal Daga Sir!

回复

要查看或添加评论,请登录

Shubham Bhalala的更多文章

社区洞察

其他会员也浏览了