Running docker containerized App from Local Image

Recently I was in a problem with setting up an application to another machine, which was perfectly okay on my machine. It was a Laravel application using docker.

So when I tried to run that app on other machine I was receiving connection refused from registry server because that app database image was hosted on a server and to access it I had to install VPN and other certificates.

docker-compose up --build

It was responding me:

Pulling database (registry.phpfarmer.com:5000/development/phpfarmer_database:latest)... ERROR: Get https://registry.phpfarmer.com:5000/v2/: dial tcp 10.16.64.80:5000: connect: connection refused

After doing some debugging and checking VPN, I found that server was down for new infrastructure implementation. So how I moved forward without making that server up again.

Yes, what I did was something like, saving my local image to a tar file and import that file in docker on other machine. Steps was mostly three line like:

docker image ls #find the image name from the list
docker save phpfarmer_database > phpfarmer_database.tar #store it
docker load < phpfarmer_database.tar #import it on new machine

After that, when I run again

docker-compose up --build

It was all fine, application started on new machine. So in summary, If you have the local copy of any docker image, you can bypass registry of it and copy it on other machine to install your app.

For more:

https://docs.docker.com/engine/reference/commandline/save/
https://docs.docker.com/engine/reference/commandline/load/

Installing and Configuring AWS CLI and Kubernetes KubeCTL CLI on Windows

In Cloud Computing industry we can say AWS is one of the most popular among others for the benefits it provides.

Kubernetes is a software for deploying, scaling and managing docker based containerized applications and it is open source. Now a days Kubernetes is getting more popular in web application development DevOps culture of it’s Portability, Scalability, High Availability and Open Source advantages.

If you have your application Infrastructure is based on AWS powered Kubernetes cluster it’s always good to install KubeCTL CLI on your local machine to skip repeated ssh to your build server to manage your Kubernetes services. Here is how you can install AWS Kubernetes KubeCTL CLI on Windows with a simple few steps.

Step 1: Get AWS CLI Client installed

First you will need to get AWS CLI Client installed on your machine, you can get it from here https://aws.amazon.com/cli/

Just to make sure if it has been installed and accessible correctly you can test it via executing below code on your windows powershell

aws --version

You will get some information like this:

aws-cli/1.16.286 Python/2.7.16 Windows/10 botocore/1.13.22

Step 2: Get Kubernetes CLI Client installed

Secondly you will need to get Kubernetes CLI Client install on your machine which you can get from https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-windows

To see if it has been installed and accessible correctly you can test it via executing below code on your windows powershell

kubectl version

Step 3: Configure AWS CLI

To configire you aws cli you will need two information like aws_access_key_id and aws_secret_access_key and you can configure it by executing below command:

aws configure

AWS Access Key ID [None]: AKIAJXXXXXXEWDNXXXXX
AWS Secret Access Key [None]: 2EqCQXXXXXuK3LXXXXXtZXMGNXXXXXVCHd0XXXXX
Default region name [None]: eu-central-1
Default output format [None]: JSON

Step 4: Configure Amazon EKS (Elastic Kubernetes Service)

To configure Kubectl you can execute below command with region and cluster name flag, make sure that cluster has been created on your aws platform.

aws eks --region eu-central-1 update-kubeconfig --name phpfarmer-kube1

if things is fine you will get some response like below response and you are done!

Added new context arn:aws:eks:eu-central-1:012345678910:cluster/phpfarmer-kube1 to ..../.kube/config

Now you can travel with kubectl locally like:

kubectl get services #to list the services
kubectl get pods --all-namespaces #to list the pods
kubectl get pods -n testing
kubectl get pods -n production
kubectl get jobs -n testing #to list all the jobs on testing namespace
kubectl delete job phpfarmer-testing-migrate #to delete a job
kubectl describe pods phpfarmer-testing-569c58cff8-k6p2n -n testing #to describe a single pod
kubectl exec -it phpfarmer-testing-569c58cff8-k6p2n -n testing bash #to get inside a pod
kubectl logs phpfarmer-testing-569c58cff8-k6p2n #to get the log of specific pod
kubectl get ingress -n testing #get all ingress for testing namespace
kubectl describe ingress internal-ingress -n testing #describe a specific ingress

There are more here https://kubernetes.io/docs/reference/kubectl/cheatsheet/

How to use Custom Network Interface on Windows

If you have some official application hosted on some private server and can be only accessed from office network, you will not be able to install VPN on your machine, because it will by default pass all the traffic through it’s own network interface. Here I will describe how to setup network traffic to use specific network interface. It will be fore Windows though Linux would be more easy because the core steps are same.

Let’s say you want to access a privately accessible application from your office network and the URL is https://erp.phpfarmer.com

In summary the main goal is to have that specific trafic through your default internal network interface not by the VPN one. You can do it in three main steps like finding the IP of you target website URL then put it on hostfile and add a new entry on route table.

Open powershell (Administrator)

nslookup erp.phpfarmer.com #find the ipaddress i.e: 10.30.20.140

After finding the IP address now update your hostfile with that IP

10.30.20.140 erp.phpfarmer.com 

Open powershell (Administrator)

ipconfig
# look for Ethernet adapter Ethernet: (internal private network)
# Default Gateway . . . . . . . . . : 10.16.0.1
route print #see the list of network interfaces for 0.0.0.0 at IPv4 Route Table from active routes list
# Network Destination       Netmask         Gateway       Interface         Metric
#  0.0.0.0                  0.0.0.0         10.16.0.1     10.16.129.225     4250
route ADD 10.30.20.140 MASK 255.255.255.255 10.16.0.1

Step 1: nslookup erp.phpfarmer.com

First step is to find the associated IP address of that domain or application URL, it should not be any normal public IP address because it’s privately accessible via your network and it has some custom IP range. i.e 10 . 30 . * . * we can get it different ways as showing below.

Assume our VPN is turned ON checking the private ip address of this domain and it’s returning me something like public information as bellow.

Server:  57.172.252.162.in-addr.arpa
Address:  162.252.172.57
Name:    erp.phpfarmer.com 

Assume our VPN is turned OFF checking the private ip address of this domain and it’s returning me something like public information as bellow.

Server:  one.one.one.one
Address:  1.1.1.1
Name:    erp.phpfarmer.com 

Assume our VPN is turned ON but we nslookup it from another machine of that same network.

Server:  muc-1-fw.phpfarmer.com
Address:  10.16.0.1

Name:    erp.phpfarmer.com
Address: 10.30.0.8 

If you normally visit the app erp.phpfarmer.com on a browser keeping your VPN OFF you can find the Remote Address: 10.30.0.8:**** on request header by browser developer console which you can open by pressing Ctrl + Shift + I together.

So now, you are sure that your private ip address of that application server is 10.30.0.8

Step 2: Update hosts file

10.30.0.8 erp.phpfarmer.com 

Step 3: find the default gateway and interface

ipconfig
# look for Ethernet adapter Ethernet: (internal private network)
# Default Gateway . . . . . . . . . : 10.16.0.1

Another way to find it is by route print, basically the first line of result where all the network request goes through a common gateway which was configured like 10.16.*.* where the second line with 0.0.0.0 is appearing because your VPN is now ON

route print #see the list of network interfaces for 0.0.0.0 at IPv4 Route Table from active routes list
# Network Destination       Netmask         Gateway       Interface         Metric
#  0.0.0.0                  0.0.0.0         10.16.0.1     10.16.128.225     4250
#  0.0.0.0                  0.0.0.0         On-link       10.6.6.99         26

Step 4: add the private ip to the route table

Here you will need to add that private IP address to the route table to use that specific default gateway of local route interface, so that we can say, all the traffic can go through VPN created network interface but only this IP request should through local network.

route ADD 10.30.0.8 MASK 255.255.255.255 10.16.0.1
tracert 10.30.0.8 #You can check now how it goes 

Now!!! If everything is fine you should be able to access with/out VPN that site!!!

Storing and retrieving session after login with Python Selenium

A simple example by which you can get the cookies from the webdriver and pickle them and save the pickle in a file; for loading cookies you can unpickle the saved file data and add the cookies to the driver as shown on below code sample.

Getting and Storing Cookies

import pickle
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://phpfarmer.com')
# login code
pickle.dump(driver.get_cookies() , open("PHPCookies.pkl","wb"))

Loading Cookies

import pickle
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://phpfarmer.com')
for cookie in pickle.load(open("PHPCookies.pkl", "rb")):
    driver.add_cookie(cookie)

Very simple, isn’t it?

Yes finally it’s been a Month!

It was 29th Mar, 2019 7:30 AM when I arrived in Munich International Airport for first time also it was first arrival ever in my life somewhere else from my home country Bangladesh. It was a flight with Singapore Airlines, previously I had no experience of any airlines services, I choose this only for 2 reason, first one is 30% around discounted ticket and another is to see the world most beautiful Changi Airport Singapore. That costs me 23 hours of journey where if I choose some others then the usual flight duration could be only 14 hours!

The first day here in Einsteinstraße München, was a bit learning and knowing each stuffs. Whatever I see and noticed almost everything is new! Faisal Ibrahim one of my ex-colleague from Aan-Nahl Software Limited he came here in this city 15 days before my arrival. and on the first day he came to visit me in my apartment. That was really helpful for me, Thanks Faisal bro again. Still now when I am writing this article I am waiting for you 🙂 to have a Khuchuri lunch together!

I leave my home village on 2001 right after my S.S.C exam. It’s around 18 years now, but it was in same country and just a division distance, and now this case it’s another Country and it’s around 7,287 km distance!! So it’s not possible for me to move anytime I want!

While I was in my home country I had really a Luxurious, Easy and Family life. As a Senior Software Engineer with 12+ years of experience it was really easy for me to live in any standard. On top of everything the only issue I was facing the security of my and my family, however Alhamdulillah Allah gave me a chance to change it, that’s why I am here to find a secured and healthy life.

Yeah, I always find myself a bit introvert, even when I was in my home country. I don’t talk first, I don’t make friends first but I look for, whenever I find it’s good to go with I do it. Though it’s a bit time consuming and in some cases I find the other person already started thinking negative about me.

Here in Munich, for at least first 15 days I was feeling too much home sick, too much alone 🙂 It’s not only me, was feeling it’s everyone alone here. They only talk whenever it’s required, they walk whenever there is a reason, they start talking to the point, with no introduction of anything. I was feeling like no this is not for me, this culture is not for me, I didn’t find any reason why I am here.

To find a solution I started talking a lot of my friends who already abroad for a longer time and family members. Everyone was saying like at-least stay for a couple of months so that you know if it is really what you are feeling now. Otherwise you might find guilty when you back here. Then later performed 2 time Istikharah salah and In a result I settled my mind to stay here  Now, it’s all easy for me. The things I was feeling not for my first few days now I find it’s for me 🙂

Now, I am enjoying staying here, now I can move around without any help. Also found a couple of Asian shops which all are full of Asian foods and stuff. It’s already been a month, expecting to visit my home within next 4/5 months.

Thanks for reading!

Setting up VirtualHost for Symfony Application on Ubuntu

If you are developing a Symfony application on your local machine by default you will get a localhost URL like:

http://localhost/symfony/symfony-test-app/public/

Which is a bit bad looking because the actual front facing application of Symfony is in app-root/public directory. You can make it look like http://symfony-test-app.com depending on your application name just by editing 2 files.

Let’s see how it works in Ubuntu:

The first file you will need to edit is virtual host configuration file or you can create one new. The root directory in this case would be: /etc/apache2/sites-available/

I am going to create a separate file for my app which is symfony-test-app.conf

sudo vim /etc/apache2/sites-available/symfony-test-app.conf

The content of symfony-test-app.conf file would be:

<VirtualHost *:80>
  ServerName symfony-test-app.com
  <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
    RewriteRule .* - [F]
  </IfModule>
  DocumentRoot /var/www/html/symfony/symfony-test-app/public
  <Directory /var/www/html/symfony/symfony-test-app/public>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

Just change the ServerName, DocumentRoot and Directory line according to your application path.

The second file you will need to edit is the hosts file. The root directory in this case would be: /etc/

sudo vim /etc/hosts

The content you need to add is just a single line like:

127.0.0.1       symfony-test-app.com

You can add it before or after the default localhost line like:

127.0.0.1       localhost

That’s it, You are ready to go by enabling your newly created virtual hosts configuration file and restarting your Apache like this:

sudo a2ensite symfony-test-app.conf
sudo service apache2 restart

If you did it all good then now you can visit your in development Symfony application by http://symfony-test-app.com/ instead of using that old ugly URL with /public at the end.

Thanks for reading.

Install WordPress via WP-CLI

If you are a bash lover I wish you will find WP-CLI is the best approach to install WordPress for your project. WP-CLI provides a command-line interface for many actions you might perform in the WordPress admin where doing those same thing via WP-Admin will cost you some extra time.

To install WP-CLI on your machine depending on your Operating System there are some requirements, please check for that here https://wp-cli.org/

Here I am going to show how to move forward with Linux with PHP version 7.0.

Installing WP-CLI

Open you terminal with CTRL + ALT + T and execute below commands one by one. If things go right I hope you are ready to test the power of WP-CLI.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

How to Install a fresh WordPress instance

To install a fresh WordPress instance move into your work directory and create a directory with your project name. For example phpfarmer.com in my case. Then change directory into it and run below commands one by one.

In the meantime I will create a database with below info:
Database name: phpfarmer
Database Username: juyal
Database User Password: 123456$$!

Also I am expecting my newly installed WordPress admin credentials will be:
Username: phpfarmer
Password: 123farmer$$
Email: juyal@phpfarmer.com

# Download and Configure WordPress
wp core download
wp core config --dbhost=localhost --dbname=phpfarmer --dbuser=juyal --dbpass=123456$$!

# Configure wp-config.php
chmod 644 wp-config.php
wp core install --url=yourwebsite.com --title="Your Blog Title" --admin_name=phpfarmer --admin_password=123farmer$$ --admin_email=juyal@phpfarmer.com

# Enable File Uploading
cd wp-content
mkdir uploads
chgrp web uploads/
chmod 775 uploads/   

If everything went right then that’s all! Isn’t it easy and fast enough? Let’s see it in action just visit – http://localhost/phpfarmer.com

Try some action with WP-CLI

May be all of them you can do via WP-Admin but clicking, page loading, navigation will wast your time for them. So here you are going to skip them to speed up your development.

wp plugin list
wp plugin update akismet
wp theme list
wp theme update twentyfifteen

Thanks for reading!

This is how I make my Development Environment Ready!

Each Time I start with a fresh Linux Ubuntu distro I faced a lot of software installation and configuration is repeating because you know we software engineers are preferred to use only those applications which is we are used to.

That’s why to get my machine fully armed from a fresh start for web application development I wrote a gist to expedite the process.. If you are a Linux Ubuntu lover I wish you will find it useful – https://gist.github.com/tojibon/6a67e8fce63e65971be2374fef2e8cfd

```
sudo apt-get install -y build-essential
sudo apt-get install curl -y
sudo apt-get install libpng-dev libjpeg-dev -y
sudo apt-get install pngquant -y
sudo apt-get install git -y
sudo apt-get install openssh-server -y
sudo apt-get install unrar -y
# Fix local issue: https://askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue

# installing VIM
sudo apt-get update
sudo apt-get install vim -y

# installing zsh
sudo apt-get update
sudo apt-get install git-core zsh
zsh --version
chsh -s $(which zsh) ============OR=========== chsh -s /bin/zsh
wget --no-check-certificate http://install.ohmyz.sh -O - | sh
vim .zshrc
alias ll='ls -l --color=auto'
alias la='ls -la --color=auto'
ZSH_THEME=amuse
reboot

# installing SDKMAN - http://sdkman.io/install.html
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk version
sdk install java
sdk current java
sdk install maven
sdk current maven

# installing Docker
sudo ls
curl https://gist.githubusercontent.com/tojibon/fadd13d9b1cc5a42f38112911c43b4d6/raw/0f369720ac0109885ffbdc2fc4840b0e50389909/install_docker.sh | bash
docker -v
docker-compose -v

# installing LAMP7 - https://www.storagecraft.com/blog/install-lamp-server-linux-mint-18-command/
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo reboot
sudo apt-get install lamp-server^ -y
xdg-open http://localhost
sudo nano /var/www/html/info.php
sudo service apache2 restart
sudo apt-get install phpmyadmin -y
sudo service apache2 restart
xdg-open http://localhost/phpmyadmin
sudo apt-get install php-intl

#installing Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
composer -V
sudo composer self-update

# installing Spring-STS - https://gist.github.com/tojibon/9e521a276cf93ac79650c8a3f68e03fe

# installing Intellij IDEA - https://www.jetbrains.com/idea/download/download-thanks.html?platform=linux
# https://www.jetbrains.com/help/idea/2017.1/installing-and-launching.html
cd Downloads/
sudo tar xf ideaIU-2017.1.3.tar.gz -C /opt/
cd /opt/idea-IU-171.4424.56/bin
./idea.sh
# https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit

#installing nodejs - https://nodejs.org/en/download/package-manager/
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

# installing yarn - https://yarnpkg.com/en/docs/install
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

# installing JHipster- https://jhipster.github.io/
sudo npm install --global gulp-cli
sudo npm install -g bower
sudo npm install -g yo
sudo yarn global add generator-jhipster

# Generating SSH Key
ssh-keygen
cat .ssh/id_rsa.pub

sudo apt-get install php-curl
sudo apt-get install poedit

# Installing Zeal
sudo add-apt-repository ppa:zeal-developers/ppa
sudo apt-get update
sudo apt-get install zeal

# Installing WP Cli http://wp-cli.org/#installing
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

# Installing PlayOnLinux https://askubuntu.com/questions/770687/how-to-install-playonlinux-on-ubuntu-16-04
sudo add-apt-repository ppa:noobslab/apps
sudo apt-get update
sudo apt-get install playonlinux

sudo apt install gnome-clocks -y
```

After installing all of these here are some software to be installed from Ubuntu software:

```
1. Kazam
2. Kdenlive
3. Skype
4. Shutter
```

Become AWS Certified Developer – Associate Level

As a software engineer I’ve been working on Web Application development career for around 10+ years, so it’s been above a decade!!

On this long career I’ve been working with AWS platform for a lot of applications and also currently managing a couple of AWS root / non-root admin account as a developer.

I was never concerned about any certification related to my career but recently I’ve found it’s really imported to get certified from some internationally popular vendors like AWS, Google, Zend etc. and In the meantime I’ve found one of my peer Shudarshon Chaki who is very keen on getting certified like Linux, AWS etc. I was inspired from him and started studying for AWS Associate Level Developer certification from may be Mar / Apr, 2018 and finally got the badge on Nov, 2018.

It’s first time I’ve received a proof of my work knowledge on any platform, the feeling is really awesome, this actually boosted up my confidence level. Now a days I am planning to start for other certifications like Solution Architect, Docker, Scrum etc certification and Expecting to own at least on within 2019.

How you can get prepared for AWS certification?

If you want to get it I will advice you to have your own AWS account mostly the trial one for one year, read Whitepapers and FAQ of AWS services. And also follow depend on some video courses provided by LinuxAcademy or A Cloud Guru. While study for certification don’t move forward fast instead try to learn the concepts, advantages, disadvantages and limitations of a feature.

Make some notes of your learning, after a few days of your study take a break for at least one week and then start again, by this way you will find yourself efficient and continuous learning without any break will make you get boring and demotivated 😦

Also another thing, focus on the syllabus – the subjects / topics of your certification. AWS is a really huge platform, otherwise you will lost yourself! After atleast 3/4 months of study I will advice you to purchase the invoice for exam and finish it within a week!

That’s it for now, If you have any specific query you can put a comment here, I will try to reply you best. Thanks for reading.

Become a Amazing Contributors of TitanFramework!

I’ve been working with WordPress a most popular free and open-source content management system based on PHP & MySQL since 2008. As a senior software engineer I find one this CMS is the best to build simple dynamic websites for my freelance and official small to medium scale projects.

From the beginning I started creating WordPress theme from scratch or building child theme and plugin for it. But then I moved to https://themeforest.net/user/codereactor like marketplaces to sell my developed premium WordPress theme and plugins I’ve found this TitanFramework is the most suitable starter framework for WordPress.

After a couple of theme and plugins development I become a fan of this Framework only for it’s simplicity of developer friendly API. Though that time it was still growing and I planned to contribute a couple of features. The first contribution was about image gallery input API and add more and drop and drop sorting. Also added some other commits. Finally somehow the core team approved my pull requested!

And this is second time my contribution was approved on open source community via Github. The feeling of code contribution pull request accepted is really amazing and on top of that published your photo on any well known website related to your career is something top of everything!!!

If you are WordPress developer I will expect you to try TitanFramework I hope you will fall in love with this!

Thanks for reading.