Friday, February 17, 2017

All about Docker Docker Cheet Sheet by Sameera Dissanayaka

Docker Cheat Sheet

Docker Cheat sheet
By Sameera Madushan Dissanayaka

Build docker image
docker build -t Sameera/Dissanayaka .

Run Docker image
Demon mode
docker run -dt -p 80:80 docker_image_name

Intaractive mode

docker run -id -p 80:80 docker_image_name bash
when you exit docker container distroyed

Check docker images

docker images

Check running docker containers
docker ps

Checke stopped docker container and running docker containers

docker ps -a

Stop running docker container
(1234 docker container id or docker image id)
docker stop 1234

Restart stopped container 

docker restart 1234

Remove docker container

docker rm 1234

Forced remove docker container

docker rm -f 1234

Remove docker image

docker rmi 1234

Identify host and container side of docker port allocation

docker run -dt -p 8081:80

8081 container
80 hostulk

Bulk remove container 

docker rm 1234 5678 1432

Bulk image remove

docker rmi 1234 5678 1432

Access the docker container

docker exec -it 1234 bash

Remove stopped docker container

docker rm $(docker ps -a -q)

Remove all the containers

docker rm -f $(docker ps -a -q)

Periodcally remove stopped containers

Create cron job to remove all stopped containers

*/30 * * * * docker rm $(docker ps -a -q)  >> /var/log/docker_removed.log

Inspect the docker container

docker inspect 1234

Check IPAddress of container

docker inspect 1234 |grep IPAddress

Link docker container db container to container mywebcontainer

docker run -d -p 8081:80 --name sameera --link db -t mywebcontainer

Change docker image name container abc in to sam

docker tag abc sam

Shared container folder with host

docker run -dt -v /var/www/hostside:/var/www/containerside  name_of_image

Shared Container

docker run -d --volumes-from nameofcontainer -- db docker_image_name

To Be Continued ....

















How to get free SSL certificate

Get free ssl certificate on apache server on Debian

1. Go  to https://certbot.eff.org  and select OS type and web server

2.Ex:- Apache on Ubuntu 16.04 
Install sudo apt-get install python-letsencrypt-apache

3.Generate certificate and insert into apache 
letsencrypt --apache
4.Automate renewal
Let’s Encrypt Certificate last for 90 days so after 90 days it should be renew
Add cron job  letsencrypt renew


How to add free SSL cert to nginx on amazon aws AMI

First download certbot and change write permission
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto
./mention installed path /certbot-auto certonly
./mention installed path /certbot-auto certonly --standalone -d yourwebsite.com -d yourotherwebsitedomain
Certification is valid for 30 days
Test automatic renew using
./mention installed path /certbot-auto renew --dry-run
add cron job to execute relevent time
./mention installed path/certbot-auto renew --quiet 





Sunday, July 17, 2016

How to create Video Upload API using Python Flask Dockers Apache2 Nginx Reverse Proxy SSL Lesson 1

Python Flask Video Upload API

#python #flask #pythondockers #pythonnginx #pythonapache2reverseproxy #pythonnginxreverseproxy #ubuntudockers
Hello and welcome to my blog.Today onwards we going to start a new journey.I'm going to teach you How to build complete video upload REST API using python flask.
so stay with me.
Here is the plan of this lesson series.around 50

  1. Introduction of the project and Setup our working environment.
  2. Create User Registration System using Python Flask.
  3. Create email Sending API for user verification Using Python Flask.
  4. Create API for verified user Identification Using Python Flask.
  5. Create API for user Login Using Python Flask.
  6. Create API for change user email using Python Flask.
  7. Create user email change email sending API.
  8. Create video upload API.
  9. create view uploaded video API.
  10. Change uploaded video details API.
  11. Delete uploaded video API.
  12. Apache reverse proxy.
  13. nginx reverse proxy.
  14. Create docker image from docker file.
  15. Create docker container from docker image.
  16. Create mongodb docker image.
  17. Link web service docker and mongodb docker.
  18. Change host file in ubuntu.
  19. Create virtual host in apache2.
  20. Create virtual host in nginx.
  21. Use unix socket insted of the tcp socket nginx.
  22. Install uwsgi and run flask app.
  23. Create wsgi and run flask application using wsgi.
  24. Commit docker.
  25. Rename docker.
  26. Restart docker.
  27. Stop docker.
  28. Restart docker.
  29. Remove docker image.
  30. Remove docker container.
  31. Stop all running docker container in one click.
  32. Remove all stopped container in one click.
  33. Use https for the flask application.
  34. Redirect http to the https in nginx
  35. Launch flask app to google app engine.
  36. Use single run command in docker file.
  37. Restart flask app if it is crashed.
  38. Run flask app using shell file.
  39. Run flask app using shell file with nohup command.
  40. Create non root ubuntu account to build and run docker image.
  41. How to run any file when docker container start.
  42. Build and run docker container and run video upload web service inside the docker file using one shell script.
  43. Use advance rest client to check your web service.
  44. Use postman to check your web service.
  45. Use curl to check your web service.
  46. How to use GET request to check your web service.
  47. How to use POST method to send request to your web service.
  48. How to use form encoded for send request to web service.
  49. How to solve url character limited nginx.
  50. How to solve apache errors.
  51. How to get POST and GET method both in flask application.
  52. What is IBM Bluemix.
  53. How to deploy docker image to IBM Bluemix. 
Plase share and comment.Have a good day


Tuesday, February 23, 2016

How to Hide Files in Windows System Using ADS(Altanate Data Stream)

How to Hide File Using Python 

Alternate Data stream is a substructure of a NTFS file system.Alternate Data Stream(ADS) can not  detect by common software or tools and it is attach with normal file or folder in hidden layer.

File Data and Attributes <--> Default Data Stream <-->Altanate Data Stream

so first create folder and inside that folder create python file name hide.py and also create text file hello.txt and also add image file photo.jpg we are going to hide this photo.jpg file inside the hello.txt file

What things we need to hide file using python
[+]install python 2.7 to your windows computer
[+]install pyADS 
open command prompt and type 
pip install pyADS


then it will install pyADS for you 
ok now open hide.py file in text editor or python IDE.i use pycharm

then type
import argparse
from pyads import ADS
we use argparse to get user input in command prompt

then create our main function
 def Main():
and create variable name parse and then it take input from argparse method
parser=argparse.ArgumentParser()
then we can get user input to scan for ADS files
Add file to ADS
Remove file from ADS
Extract ADS file

parser.add_argument("file",help="Specify File or Directory")
parser.add_argument("-o","--output",help="Print output to terminal",action="store_true")
parser.add_argument("-a","--add",help="Add stream to <file>",type=str)
parser.add_argument("-e","--extract",help="Extract All",action="store_true")
parser.add_argument("-r","--remove",help="Remove All",action="store_true")
 
Whole Program
import argparse
from pyads import ADS


def Main():
    parser=argparse.ArgumentParser()
    parser.add_argument("file",help="Specify File or Directory")
    parser.add_argument("-o","--output",help="Print output to terminal",action="store_true")
    parser.add_argument("-a","--add",help="Add stream to <file>",type=str)
    parser.add_argument("-e","--extract",help="Extract All",action="store_true")
    parser.add_argument("-r","--remove",help="Remove All",action="store_true")

    args=parser.parse_args()
    if args.file:
        handler=ADS(args.file)

        if args.add:
            handler.addStream(args.add)
        if handler.containStreams():
            for stream in handler.getStreams()[:]:
                if args.output:
                    print(args.file+":"+stream)
                if args.extract:
                    fh=open(stream,"wb")
                    fh.write(handler.getStreamContent(stream))
                    fh.close()
                if args.remove:
                    handler.removeStream(stream)
    else:
        print(parser.usage)



Main()
Lets try it
hide file inside
see text file size is 0byte


 open folder and type cmd then it will open Command prompt from there
so type python hide.py hello.txt -a photo.jpg 


now it will combine the photo inside the text file we can check it using python hello.txt -o to scan the ads file see now photo is inside the text file.

now we can check the text file size it is still 0byte

so we can delete the photo.jpg 

now let's recover our hidden photo from text file
python hide.py hello.txt -e


this will extract photo.jpg from hello.txt file 

i hope you would enjoy this tutorial.if you are like this post please share with your friends.

Commands

python hide.py hello.txt -o  To check is there any ADS files
python hide.py hello.txt -a photo.jpg to hide photo inside text file
python hide.py hello.txt -e to extract photo from text file
python hide.py hello.txt -r to remove photo from text file
if you have face error add pyads file to same folder
download






Android Studio not Open After Installing

android studio java.lang.RuntimeException: java.lang.IllegalArgumentException: Argument 


if you are try to install and open android studio for the first time sometimes you may have face to this error .
i also face the same problem .here is the tip for solve the this error and have fun with android app coding

there is two things you can solve the problem
1.disconnect your internet connection and close your android studio and restart android studio.this will help to solve problem
2.Go to android studio Bin folder where you have installed android studio.

and open bin folder there is file name idea.properties 

copy that file to your desktop because that will not edit there and save there.so open copied file in desktop through notepad
then at the end of line add 
disable.android.first.run=true at the last


then save file .make sure save as all files otherwise it will save as text file

then copy and replace the file in bin folder
 then run android studio it will works well now
if you are like this post please comment bellow .and share with your friends

How to install Selenium in python Windows PC

Install Selenium in Python 2.7 For Automation

Selenium is the web driver use for use Test automation.Selenium can use for most of the testing and Automate the software product.and also this can be use for automate the boring stuff with your programming knowledge.in next tutorial im going to teach you a how to automate the LinkedIn Profile views and increase the you are getting job.and expose your LinkedIn profile to others.so before we are going to do that we have to install selenium web driver to your computer.
you will need python 2.7 in your computer
and you need PIP for this python installer package 
open command prompt and type
 pip install selenium
you can activate the pip using add C:\Python27\Scripts line to your environmental variable.see my previous post for how to do this



If you are like to this post Share and comment

How to enable dot net 3.5 (dot net 3.0 or dot net 2.0 ) offline

Install dot net 3.5 framework offline

when you try to install new software in windows 8,or windows 8.1 or windows 10 you will face this problem because windows 8 or 10 does not include the dotnet 3.5 framework.so there is option ,either you have to download dot net 3.5 framework and install it.but do you know if you have windows 8,8.1 or windows 10 DVD or iso file you can easily install dot net 3.5 framework offline
it is simple
 fi you have windows DVD put dvd in to laptop and it will mount .
when the dvd is mounted there is folder called Sources-->SXS
in my laptop it mounted as Drive Letter E so the pasth is
D:\sources\sxs

so open command prompt in administrator mode. you can do this press windows key on keyboard and type CMD. then it will show command prompt then you can right click on common prompt and provide run as administrator

in this command prompt type
Dism.exe /online /enable-feature /featurename:NetFX3 /All /Source:D:\sources\sxs /LimitAccess,

then it will automatically install dotnet 3.5 framework for you.

I hope this article will help you to solve your problem
if you are like this post please share with your friends.