I havent been really gotten into dockering much. Although I used on my wordpress development stuff using docker-compose. I get the idea behind it. But right now , I just wanna go at it from the beginning. To refresh my memory.
We know so far, docker containers are created from an image. You either create your container from a dockerfile inside a folder or create it via command line. First we need to familiar ourselves with some commands. Also refer to this site for the list of commands
docker build -t [image_name:any_tag] [context_path or path_to your_dockerfile] – build the image based on a docker file. -t option is to name your image.
docker run -p 8084:80 [image_name] – this is to run the image that were created. -p is the port we need to expose to access the container port. 8084 is the port of the host pc and 80 port of the containers. -v mounting a volume so you can change the files inside the container folder. -v [absolute_path:container_path]. Important note: relative path for host doesnt work and must be an absolute path for the host. Funnily enough relative volumes on docker-compose works.
docker ps – basically list all running containers running so far. You can use -a to also shows non-running containers.
docker image ls – list all your images currently available.
docker rm [container_id] – remove the container
docker image rm [image name:latest or image_id] – remove the image. -f force image to be deleted.
docker stop [container_id] – stop the container from running.
Few months ago I have started developing a hybrid mobile app using Cordova. I encountered a lot of headaches and frustrations using this technology but the more time you spend on it, the better you get at googling about your issues (lol). Here I list all my headache and quirk fixes I found make it at least bearable to develop for Cordova.
Apache Cordova is Phonegap/Ionic . Phonegap and Ionic builds on top of Cordova so most likely ionic or phonegap plugin will work with Cordova.
Use the latest version of Cordova. If for some reason the current version is spitting out errors , use Cordova 8. npm install -g email@example.com as this is a stable version.
Accessing photos , camera, videos and files. If by any chance you need to access the local resources of the device. Use
Fetch() is a function that lets you grab the blob of the file to be inserted into formData to submit files to the server. It works for base64 encoded data or localhost file such as ‘/path/to/something’
Keyboard is recently my main issue making chat system by having a text field on top of soft keyboard. Use cordova-plugin-keyboard (iOS) , cordova-plugin-ionic-keyboard (Android) . Make sure you havecordova-plugin-ionic-webview installed otherwise on iOS you will see a black panel when keyboard is up. And since you are using ionic webview, you must add <preference name=”ScrollEnabled”value=”true”/> to enable body scrolling particularly with iOS.
Chat feature , creating a chat feature in cordova is hard/tricky. Remember when the soft keyboard in iOS is up , position: fixed wont work anymore. Remember to Keyboard.shrinkView(true); (disable by default) for the view to shrink and make the div bottom: 0px to attach to the keyboard. It will also help to
Keyboard.disableScrollingInShrinkView(true); to disable any scrolling while the soft keyboard is up. Put them back to normal afterwards.
Its basically a way to white-list a certain website/domain to access your page. By setting this up, for any reason a script was loaded to your page and sourcing a certain file from unknown domain, then browser will stop it from doing so.
As you might have guess, its for security purposes. I have to consider it while developing a cordova app. As Android and iOS have some stuff(required) in it for it to actually work plus it makes your application a bit more secure. Of course in general when you are building a website its nice to know these things 🙂
Below is a brief explanation about it. And if you dont understand what I mean, check the link below and you’ll get the gist of it.
For example: script-src ‘self’ https://mysite.com htts://site2.com
This means only a script from ‘self’ (local) and a script from mysite.com and https://site2.com is able to be included and run. But there is also another thing to be aware of, any script from the allowed domain cannot run any on* code or eval() code. Just in case your trusted domain try anything to change how your site behaves.
To allow them to do so and you trust them completely. You must add ‘unsafe-eval’ and ‘unsafe-inline’ and this becomes
There is a directive called ‘default-src’ meaning this becomes a default for any other directive you did not specify. For example style-src, font-src, img-src etc. If the policy does not match your default-src then the browser wont allow it.
I have finally entered the world of mobile app. Namely Cordova. Before anything else … Its a pain. Nothing like elbow grease! For anyone reading this section, and you are starting out on your journey with hybrid-app, especially when you develop in Visual Studio. DONT DO IT. Anyways as I learn the hard way, I thought VS can make the installation of packages easy, as it turns out It did not.
How to set up your Windows for Apache Cordova (Not in order)
Run npm install -g cordova
Install Java (JDK)
Add the /bin folder to the PATH
Add a new environment variable named JAVA_HOME and set value to the JDK path.
Depends where you extracted /android-sdk, /gradle and android tools.
Install Cordova via NPM “npm install -g cordova”
Install iOS-sim and iOS-deploy “npm install -g ios-sim ios-deploy” Lets you deploy to simulator and device.
Then you can start creating projects using “cordova create myapp me.domain.myapp myapp”
After you created your app and adding a iOS platform. You would build it “cordova build ios”. And the .xcworkspace in the platforms/ios/ folder must be opened in Xcode and you would build it from Xcode.
Notes: AVD Manager manages virtual devices while SDK Manager manages APIs currently installed on the system.
Run “cordova emulate android” to deploy application to virtual emulator device.
If you are using AVD(Android Virtual Device). And run your emulator and get “PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT”. Set your environment to where your android-sdk is, and this should fix it. Note: You would need HAXM Accelerator and you will need Hyper-V disabled if you are using Windows. Download and install this in the SDK Manager.
And just bite on something and hope for the best. You will want look how to deploy and debug your app. I recommend using Visual studio code -> cordova plugin. It allows you to have a emulator for the browser to just hammer on development.
With the Apache server. There is this way to handle scripts. There are 2 protocols that Apache uses CGi and FastCGI. Cgi is not used anymore as this is old and slow. FastCGI now is basically the default.
In relation with PHP script. Like any other script in Apache. You can treat this scripts by “handlers“. There are few ways to handle PHP depending on your needs.
So basically these are modules that can be installed and set depending on your needs.
See link below for detailed information. Thanks to them I finally understand the mystery.
I spend a lot of hours to do this , so I dont forget how it all works and all. ZeroMQ is a PHP extension that allows PHP to do Websockets for live communication. When you do your development specially on a Windows platform , Wamp is just my go to program to install to do some easy PHP development.
Follow these step:
After downloading and installing WAMP Server.
Download the DLL extension https://pecl.php.net/package/zmq . Make sure you download the version for the PHP you are using. There is some stuff you need to consider before attempting this and making sure you get the right one.
Thread Safety or Non-thread Safety. Make sure you choose the one appropriate with your PHP installation. Check phpinfo() to see whether its TS or Non-TS.
Also check you have the Visual C++ Redistributable installed. Again see the version of VC++ Redistributable you need in phpinfo() VC11 is usually version 2012.
Finally check whether you are running x86(32bit) or 64 bit version of WAMP.
Then move php_zmq.dll in your EXT folder of your PHP directory.
Importantly either/both copy libzmq.dll in your root PHP folder or APACHE folder. This is the one Im having issues with.
Now add a line in your php.ini “extension=php_zmq.dll” through your wamp icon and inside your PHP folder ini. This allows zmq loaded on your CLI too.
When you restart WAMP and you dont see any changes happening. Check for the PHP_LOG if there is any error. Usually there will be but if not. You are good to go. Also RESTART WINDOWS. And double check in your phpinfo() if the extension has been loaded or not.
And you should be done!
IMPORTANT NOTE AND TIPS:
Sometimes or most likely WAMP will complain about PHP folder is in your PATH environment variables. We definitely want PHP on there and Composer need this path. You can ignore the error by going to WAMP icon right click on it and go to WAMP settings and check “Do not verify path”.
Please be aware this might be an issue with WAMP. WAMP allows us to change version of PHP to use. So know that when you are changing PHP version. Better to remove PHP path from the environment variables and restarting before changing PHP version to prevent any issues.
Although Its weird that to use ZEROMQ we definitely need the PHP path there to save us time from typing the whole complete path PHP cli. Remember WAMP is just our development platform. You can probably get away from WAMP and use DOCKER instead but WAMP is just so easy. But that is just a topic for some other time.
When you create your docker file, you don’t want to just copy your whole directory in a folder. As everytime you run your docker image because you changed your source code, it will keep on installing fresh dependency packages all the time. And this will become slow.
Remember every RUN you make on docker, creates a layer on top of the image. This layer get cache. So everytime you build your container if nothing has change from your package requirements , it will use the one from the cache making it faster to rebuild.
This technique works for any projects. Like python(flask) or nodejs(package.json). Footnote though and what to watch out for. If your package requirements always points to the latest, you might want to have a fixed version number otherwise if you like to get the latest version of the packages. You might need to clear your cache to get a fresh updated copy in your container.