piątek, 30 września 2016

Run PostgreSQL using Docker with persistent data on Windows 10

Hello :-),

Recently I try too learn docker and how to use it, because I want to use it on my team.

For start I only need this as development environment on developers local machine. The task was simple, for now I just need start PostgreSQL and Redis, there are plenty information on the Internet how to start those containers and how to prepare docker-compose to start those two services, but there was ONE BIG PROBLEM I want my database data to be persistent so after we setup database and insert data and machine restarts or shutdown data will not be lost.

Well, the problem began..

I was not able to find one clear way of doing this on Windows.. I use docker version 1.12 for Windows.



 So I created this docker-compose.yml file after some articles. I try to persist data on the host machine...

So I start it with docker-compose up and both services: postgres and redis started and I was able to access it and create database with data, I was so happy when I run command docker-compose down and once again docker-compose up and saw that my database still exists without recreating!! Yes!!

I was little suprised that folder on my host C:\Users\Łukasz\dbdata which I put in docker-compose file was epty, I thougt that there should be some postgresql files in it...

But it works so propably my task was over..... not so fast, I need to restart my Windows, and after this I was suprised after launch docker-compose up.. my database with data was gone :-(.

Ok So I will try to read how to mount folder from host machine to docker containr in Windows. so I ended with this error data directory "/var/lib/postgresql/data" has wrong ownership and for now I gave up trying to mount volume on host machine.

So I go with this steps when I try to mount volume on host machine on Windows:

1. I share my C: and D: drive in docker settings


2. As a credential I put username with computer name RISCOLAP\Łukasz or using ip address like this: 10.0.75.1\Łukasz, when we put just username we are not enable to list shared folders.

3. Next I create folder data on my C: drive and put file on this
4. After this when I run command docker run --rm -v c:/Users:/data alpine ls /data I saw my file


5. I try to start postgres container with my host volume: At start everything was looking really good. Folder on my host was filled with postgresql files!!
And then I saw this error on console :-(, and my joy was over.

waiting for server to start....FATAL: data directory "/var/lib/postgresql/data" has wrong ownership HINT: The server must be started by the user that owns the data directory.

For now I do not find answer how to deal with this error. So for now I stop trying mount host folder as volume.

And I found working solution with docker volume without host volumes. So first we need to create volume with and then using this volume I create my docker-compose file like this:
And it works!! I can now restart my machine, shut down, and my data are safe!!! If you want more technical info I put some links I was reading during my searching of the solution:

piątek, 26 lutego 2016

Angular 2 Component - select property... ohhh I mean selector :-)

I wondering is there a way to mark some properties of Angular2 component as required as for example selector property?

I assume that the selector property is specific for browsers, and maybe on another platform this property is not required, but as far I use bootstrap to launch my app, Angular2 know that I will lunch this in browser, so maybe a small error like, "component [xxx] dont have selector property", would be a nice thing :-)

I just spent almost one hour wondering why is my code not working, where I did very simple example based on tutorial from Angular2 website to just show one component in another component.
Below I put example of my invalid component :-) of course this will not work, but I dont get any error about this situation in console. Of course as always it was my mistake. I made a typo :-(.



I really like Angular2 but there are so many things to learn in this framework, that this kind of property checking as some additional option to switch on would be great and help a lot.


Just my thoughts, or maybe I just need to buy glasses :-)

środa, 17 lutego 2016

ES6: Const or let or var?

ES6 / Es2015 introduces a lot of new extensions to the JavaScript world. One of these extensions are two new keywords used to variable declarations. So now in addition to the old var keyworld we have got let and const that allows us to declare a variable with a block scope. Oh great it may seem, we have so much choice, but the choice becomes problematic when it comes to writing code …

Suddenly you start writing code, you need to declare a variable and … there are questions like: when I use const, and when let, can I still use the var? These types of questions began to appear also in my team when we started to write in Node.js with ES6. It was important for us because we want in a team cohesive approach to the declaration, and because each member had a little different view of this, we had to discuss it …

First, we got acquainted closer with the let and const. about which many people have already written nice articles. I pasted below some interesting links to this topics.

https://davidwalsh.name/for-and-against-let
David Walsh Blog. For and against let Examining JavaScript ES6’s new ‘let’ keyword block for scoping, and conditions where it should or should not be used.
http://blog.getify.com/constantly-confusing-const/
Tearing down the confusions around the ES6 ‘const’ keyword
https://ponyfoo.com/articles/es6-let-const-and-temporal-dead-zone-in-depth
Pony Foo. Let ES6, Const and the “Temporal Dead Zone” (TDZ) in Depth This is yet another edition of ES6 in Depth. First time here? Welcome! So far in the covered destructuring, template literals,> arrow functions, the spread operator and rest …
and the last https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/

Discussions on how to declare variable led my team to a discussion at the workshop within the company. Effect of such a summary here…

Steps to follow when declaring variable:

  1. If the variable is used throughout the function, use const or if a variable need reference rassigned , use var
  2. If you need a variable with block sopce (for example, in if condition), use const, if variable need to be assigned to a another object, use let
  3. use let with for (;;) loops.
As you can see we we initially start with const, becouse thanks to this we secure ourself from accidently reasigned veriable.You need to remember that With const you only receive unchenged reference to object but you can change objects properties. Objects declared with const are not immutable unless you use Object.freeze() (of course with nested object you shoul use Object.frezee() with recursion).

Quick summary

Is it realy worth it to follow some trends, fashion, not understanding why you should use this approach over another, or maybe it just because it looks prettier in the code? Why I should not use var if I know that my variable which I declared on top of the function will be used all over the function body…
My small advice, learn/read about new stuff to get better understanding and do whats best fit to you and your team and stick to those choices…