Run a MySQL instance with docker

I wanted to use docker to run MySQL in isolation so i could change it’s version/state at anytime.  I see a special benefit when running MySQL or any application in a isolation where it does not depend around host machines file-system or Operating system, which means it allows us to run any available version instantly. Also they’re highly portable.

In this example I’ve used official docker-MySQL to run instances. Official image is flexible to configure around our specific needs and it’s been well documented.

Please refer to official docker-MySQL page for more configuration options.

 

Following Makefile allows to run persistent and non-persistent MySQL instances which opens up port 3306 on host machines to containerised MySQL instance. Current MySQL version  is 5.5 and default persistent directory been set. Feel free to change as required.

https://gist.github.com/KasunDon-awin/85c331de7f2f81579135530d51342764

Download above file and called it as mysql-server or any name you wanted. Then simply execute following commands in order to launch/stop/restart instances.

If you need persistent MySQL instance to be launched use

make -f mysql-server start-persistent

or use following for non-persistent instances

make -f mysql-server start

Stop or restarting instances can be done as below,
make -f mysql-server stop
make -f mysql-server restart

That’s all you can access your MySQL instance with your default mysql-client.

mysql -h 127.0.0.1 -u root

Login to AWS EC2 instances

Recently I’ve started to use AWS (Amazon Web Services) to host few of my web apps. I’ve had a little hard time to figure out how to access instances using *.pem file associated while i was creating AWS Instance.

First of all, locate pem file and assign appropriate permissions to it.


chmod 400 /path/my-key-pair.pem

Then depending upon OS (Operating System) of your ec2 instance you’ve created, you’ve to access appropriate user in order get into your ec2 instance.

Amazon Linuxec2-user
RHEL5root | ec2-user
Ubuntu – ubuntu
Fedora – fedora | ec2-user
SUSE Linux – root | ec2-user

All Others OS’s – root | ec2-user  or check with your AMI provider.

user_name@public_dns_name

For Example
ssh -i /path/my-key-pair.pem ec2-user@ec2-121.compute-1.amazonaws.com

More information please refer to AWS Official User Guide.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

Sync to containers using File Watchers

I think most of us, using docker to run applications simultaneously in one host machine. May be some of you already using docker containers as development aid tool rather than using it’s production capabilities, it’s a bit not ideal when you have to build docker images each time you making a changes to your application sources while it’s running on docker,  It take some effort to rebuild and re-run containers,  Whereas we build images which are ready to deploy or make releases.

This is why i was looking for some syncing tool that sync changes to running docker containers simultaneously. There are lot of other method we could do similar task, but found way to use PHPStrom to do this task using it’s file watchers.

FileWatchers are pretty good feature comes with PHPStrom IDE which can be used for other similar where necessary,

Here’s how i did it..

First of all open up a project, then File -> Settings [Ctrl + Alt + S]

File_Settings

Then it’ll open up Settings window, choose Tools -> File Watchers

Tools_File_Watchers

Next Click on Green add (+) button on right top to add a new file watcher. There are predefined file watcher available to choose from but this instance we’ll choose custom so we can define our own file watcher rules.

choose_custom

 

Now New Watcher Dialog will appear on your screen, this is where we define routines for our own file watcher.

new_watcher

We can fill in watcher name and description fields to identify particular file watcher.

You can define any specific File Type to be watched and Program to be called if any changes been detected to any watching file type. Also you can add extra configurations options depending upon your needs. There are lot of predefined macro’s available to try out!.

Finally!, Select File Watcher and Press Apply and OK.

select_watcher

You’ll notice whenever you change watching file type it’ll automatically sync that file into docker container instantly. If there’s a error it’ll load up failed watcher command in console. so you can identify the problem.