Thursday, September 20, 2018

Basic Docker Commands

Image is a class and container is an object of the class


To delete a container
=====================
docker ps -a //The command docker ps only displays running containers. To see all containers, including the stopped ones, use the -a parameter:
docker rm -f
docker system prune //clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):


How to see the log of a container
=================================
docker logs bcsandbox //every time the container starts is logs some important information like admin password etc


Get a list of images
====================
docker images or docker image ls


Run an executeable on a docker image (test is the container)
====================================
docker exec -it cmd //it stands for interactive 


Spin a container from an image (or create an object from a class)
==============================
docker run [options] image[:tag] [command] [args]
eg:
docker run -e accept_eula=Y 53ee8b0703ad //53ee8b0703ad is the name of the image


-e stands for an environment variables

There are certain environment variables that used by Navision images
--hostname (-h) specifies the hostname of the container. This is the name you will use to connect to the containers web client and the name you can ping. If you do not specify the hostname, the first 12 characters of the container Id will be used as the hostname.
--name specifies the name of the container. The name is used when referring to the container with other docker commands. If the name is not specified, a random name will be generated using a verb and a name (like friendly_freddy)
--memory (-m) specifies the max. amount of memory the container can use. The default for this option depends on how you are running the container. When you run Windows Server Containers there are no implicit memory option and the container can basically use all memory available to the host. When you run HyperV containers, the default max. memory is 1Gb.
--volume (-v) specifies a folder from the host you want to share with the container and the path inside the container, where you want to mount this folder. --volume c:\myfolder:c:\run\my shares the existing c:\myfolder on the host to the container and the content is in c:\run\my.
--restart specifies the restart options for the container.


command :
docker run -e accept_eula=Y --name bcsandbox -h NAVBC -m 4G -e useSSL=N  -v c:\myfolder:c:\run\my --restart always -e exitonerror=N -e locale=en-us microsoft/bcsandbox

to start using my license file placed in c:\myfolder
docker run -e accept_eula=Y --name bcdev -h DEVBC -m 4G -e useSSL=N  -v c:\myfolder:c:\run\my -e licensefile=c:\run\my\alfazance.flf --restart always -e exitonerror=N -e locale=en-us microsoft/bcsandbox


elaboration:
Which will accept the eula and run the dynamics-nav:devpreview container with 4Gb of memory, test as the name and hostname, http (not https), restart option set to always, locale to en-US, and use the licensefile, which is located in c:\myfolder\license.flf on the host computer.



//Publishing the Docker images on the Network
1. Stop any running containers -> Docker stop bcsandbox
2. Stop the docker service -> Stop-Service Docker
3. Remove the current Containe network-> Get-ContainerNetwork | Remove-ContainerNetwork -Force
4. modify daemon.json file -> '{"bridge":"none"}' | Set-Content C:\ProgramData\docker\config\daemon.json
5. create transprent network (use of of the two commands) -> docker network create -d transparent tlan
New-ContainerNetwork -Name tlan -SubnetPrefix 192.168.0.0/24 -GatewayAddress 192.168.0.1 -Mode Transparent -DNSServers 192.168.0.164,91.74.74.74
6. Start-Service Docker or restart the docker service
7. Run a container with the new adapter created ->
docker run --network tlan --ip 192.168.0.58 --name devcontainer -e accept_eula=Y -h BCDEV -e username=admin -e password=pass@word1 -e useSSL=N  -v c:\myfolder:c:\run\my -e licensefile=c:\run\my\alfazance.flf --restart always -e exitonerror=N -e locale=en-us microsoft/bcsandbox


 Create an container using navcontainerhelper
 ============================================
new-navcontainer -accept_eula -includeCSide -containerName test -licenseFile c:\myfolder\alfazance.flf -imageName microsoft/dynamics-nav:devpreview
new-navcontainer -accept_eula -includeCSide -containerName test -licenseFile c:\myfolder\alfazance.flf -auth NavUserPassword -imageName microsoft/bcsandbox


commit container as a new image
===============================
docker commit navcontainer navbcuaeloc/ver1:lan adapter changed
docker run -d navbcuaeloc/ver1


Fixing the Error = HNS failed with error : Element not found.
=============================================================
link https://github.com/docker/for-win/issues/750

stop-service hns
stop-service docker
del 'C:\ProgramData\Microsoft\Windows\hns\hns.data'
start-service hns
start-service docker

C:\myfolder\\CleanupContainerHostNetworking.ps1 -Cleanup -ForceDeleteAllSwitches
Restart-Computer -Force




docker run --network tlan --ip 192.168.0.59 --name bcangshudev -e accept_eula=Y -h BCANGSHU -e username=admin -e password=pass@word1 -e useSSL=N  -v c:\myfolder:c:\run\my -e licensefile=c:\run\my\alfazance.flf --restart always -e exitonerror=N -e locale=en-us microsoft/bcsandbox
docker run --network tlan --ip 192.168.0.60 --name bckirtidev -e accept_eula=Y -h BCKIRTI -e username=admin -e password=pass@word1 -e useSSL=N  -v c:\myfolder:c:\run\my -e licensefile=c:\run\my\alfazance.flf --restart always -e exitonerror=N -e locale=en-us microsoft/bcsandbox

New-NavContainer -containerName bcsan -accept_eula -alwaysPull -assignPremiumPlan -auth NavUserPassword -doNotExportObjectsToText -enableSymbolLoading -imageName microsoft/bcsandbox -includeCSide -memoryLimit 3G -shortcuts Desktop -updateHosts



CONVERT OBJECT TO AL
====================
Get-Command -Module NavContainerHelper
Export-NavContainerObject -containerName devcontainer -objectsFolder c:\myfolder -filter 'Type=Report;Id=206'
Convert-Txt2Al -containerName devcontainer -myDeltaFolder c:\myfolder -myAlFolder c:\myfolder\al -startId 70140931

Git Basics

Git is a local version control tool. Git also has an online centralized repository which is known as GitHub.

Getting started
  • Once you have installed git you can use the GitBash console to configure the local git. 
  • git config --global user.name "abc@abc.com'"
  • git config --global user.email "abc@abc.com"
  • git config --global core.editor "code --wait --new-window"  
The global setting are saved in an xml file on the  as done above can be viewed using
  • git config --edit --global 
connecting with the GitHub might require the user name and password to be authenticated each time. This can be avoid by using the SSH connection to the GitHub. To generate an SSH key use the command prompt and type the following command:
  • ssh-keygen -t rsa -b 4096 -C "yourmail@domain.com"
Before the next step, please ensure that the service for ssh is running in windows services "Open-SSH authentication agent". Please ensure that that you are in the %userprofile% directory before you issue the next command you can do 
  • C:\cd %userprofile% 
  • ssh-add ./.ssh/id_rsa : This command will add the identity created to the ssh agent running
  • cd .ssh
  • type id-rsa.pub 
Goto gitHub-> Profile -> settings and add the contents of the id_rsa.pub to the ssk section and give it a description from which computer this was added. To test if the ssh connection is working fine please use
  • ssh -T git@github.com


Concept
======
Git is a distributed source code management software. In centralized VSS tools entire history is on the central server and only the latest copy (checked in version) is in the local directory. In git the entire history of all the versions and check ins is on every local copy as well. 
  • Branches : These are features being worked on. A branch is created locally and when finalized is pushed. One user can be working on multiple features at the same time and hence can have multiple branches open at the same time. 
  • Push : process of sending finalized changes to the GitHub 
  • Pull : process of pulling the latest copies from GitHub 
  • File states
    • Committed : stored locally
    • Modified: changed but not committed 
    • Staged : marked for next commit.snapshot. 
  • File areas
    • Working directory: editing areas
    • Staging : files waiting for the commit
    • .git repo : committed files
  • Repositories: its a folder for your project integrated with git. A new  

Git process outline:
=============
  • git init : creates a local repository
  • git clone: clone a repository into a local directory and create a remote branch
  • git add : add a file into the staging area
  • git commit: commit the changes to the local repository
  • git push origin master: push the changes from the local master to the origin (remote repo)
  • git pull remote master: 
Branches:
=======
In a nutshell a branch is parallel copy of the original source code which can at sometime be merged into the original source. In traditional system this was done using a copy of the source being hosted as a separate repository. 

Git is based on snapshot (differential and not incremental changes) and hence its easier for Git to implement this concept. Each commit creates a differential snapshot and files changed are marked in the snapshot. If a file is not changed it remains pointed to the original commit pointer. Hence a branch is also a pointer to one of the commits

The master is the default branch and it always points to the last commit made. It also automatically moves forward when a commit is made. 

Branches should be used to work on a feature and should only be committed to the master once completed and tested. To avoid conflicts the branches should be logically arranged to avoid the same object in multiple branches, this would ease the merge operations. 

  • git branch <branchName>: This command is used to create a new local branch. 
  • git branch -a : This command will give a list of all the local and remote branches. 
  • git branch -vv: This command will give the local branches and their corresponding upsteam branches on remote repo. 
  • git checkout : At any given point there can be multiple branches that are active and the active branch can be changed using checkout command. If the branch is missing it will get created. 
  • git checkout -- . :this command can be used to discard all the unstaged changes and revert to the last committed stage on the current branch.
  • git push -u origin <newbranch>: This command pushes the branch created locally to GitHub make sure the branch name is same locally and on remote. 
  • git fetch : This command is used to fetch any branch from GitHub to the local repository. 
  • git pull : this is used to merge branches. A pull request is from the owner of the branch to the owner of the master branch (collaborators) to merge the changes.
  • git log --all  --oneline --decorate --graph: This command can be used to look at all the commit log and branches there are. 
  • git --rebase:  If you don’t want a bunch of commits in a pull request, you may need to use git rebase to “squash the commit history”.
Remote repo
========= 
remote repositories are the once located on GitHub. Origin keyword in an alias that is created by default for the remote repository if a name is not specified when we clone it. Alternatively if we initialized a local repo (not cloned), we can link it to a remote repo using: 
  • git remote add origin https://github.com/santoshkmrsingh/abc.git

we can also have multiple remote alias created (this would be logical when we are using forks (copies) of the same repository)
  • git remote add afzMobile https://github.com/Alfazance/mobile.git

given the above two commands we have two remote alias created. These can be seen using 
  • git remote: refers the link to the master branch on the remote repository.  
  • git remote -v : list the full details of the remote links
remote tracking branch tells us what the current branch looks like at origin. The remote tracking branches cannot be directly worked at. We will always work with local branches. 
  • origin/master : refers to the master branch on the remote repository. 
  • git merge origin/master: merges the current branch with the remote repository 
pull and push
==========
pull and push work from the local branch to a corresponding branch on the remote repository. It hence important that before a pull or a push is used, the local repo and branch have a corresponding link to a remote repo and a branch. A push always works from the current local branch to a branch on the remote repo. Hence, it is important that before a push request is issued the correct branch is checked out. 

To link the current branch to one on the remote, you can use the  following command. 
  • git branch --set-upstream-to origin/branch: This command is used to link a local branch to a branch on the origin
Once the link is established the following commands can be used to push the local commits to the remote repo
  • git push : this command will push the contents of the current branch to the corresponding branch ont the remote server
  • git push -u origin: : this command will push the contents of the current branch to the branch on the remote repo. If the branch does not exists on the remote repo it is created.
    Note: the branch name on the local repo should match the branch name on the remote. You cannot push changes from one branch name in the local directory to another branchname on the remote. 

Pull request:
Pull request can be more relevantly called merge request. Once the local contents have been pushed to the remote server the pull request can be used to merge these changes on the master branch. 

To have better control we can configure the pull requests branch rules (in settings on GitHub) where we can configure options like merging can only happen through pull requests and not directly through a local merge. 


Merge:
=====
Merge is used whenever there is a conflict i.e more than one user has made a change on the same file and same line. Merge can happen locally or on the server. 

If the local timestamp of a file in a branch is older then the one on the server, then the same should be locally merged (using a pull command), before it can be pushed up.  For the below commands please assume that we have the master branch checked out
  • git merge feature: this command will merge the feature branch into the current branch (master in this case) along with all the commits of the feature branch.
  • get merge --squash feature : this will merge the feature branch into the current branch (master) without the commit history of the feature branch.This should be followed by a commit on the master branch git commit -m "squashed commit with features".
  • git rebase master: If the current branch has a base in the master, the rebase will bring the latest commit from the master into the current feature branch and reapply all the local commits in the feature branch on top of it. Thus we will have a new base with the latest changes from master. 
  • git reset --hard <commitid>: This command deletes all the commits post the commitId this can be used to undo any unwanted commits.  
  • git stash : stash commands can be used to undo and redo changes in the current working tree. This command can be used to revert all the current changes and revert to the last clean working directory status. Each time a stash command is used the changes are pushed to the stash list. 
  • git stash push -m "comment" : this can be used to push a change to the stash with a custom message.
  • git stash list : this can be used to list all the changes that are pushed to the stash.
  • git stash apply:  will reapply all the changes that are parked in stash. If there are a no of stash on the stack we can choose which one to apply from the list using its index. 
  • git stash drop <index>: this can be used to drop a given checkpoint from the stack.
  • git stash clear : can be used to clear the stack maintained for stash.


Fork:
====
Fork is just a copy of the repository. Any changes to the fork does not impact the original repo. This is however internally still linked to the original repo. All the other commands to interact with a fork are the same as with any GitHub repository. 

Forks are very useful when it comes to accepting public contributions to your repository. One would not want changes to be done to the original repository, hence full access is provided to forked copies. Changes from the forked repository to the seed repository can only be done by the developer who has an write access to both the repositories. 

While working with a scenario like this, the need to have multiple named remote repositories might get evident.

$ git remote -v
> origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
> upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
> upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

In the example above the origin would refer to the clone repository created on GitHub and upstream is another remote link added to the original seed repository. Additional remote repo link is creating using :

$ git remote add upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

If you are hoping to contribute back to the original repository, you can send a request to the original author to pull your fork into their repository by submitting a pull request.

NOTES
=====
1. HEAD refers to the changes in the current branch

2. When prompted for message
press "i"
write your merge message.
press "esc"
write ":wq"
then press enter.

3. Create a file not possible using windows explorer (eg. a filename starting with period(.))
touch

4. To see a history of commits
git log --oneline --decorate --graph --all

5. Edit the .gitignore file
That can be done using the vim editor.
Simply type vi [path-to-file]\file and you will open the vim terminal editor.
Press a to toggle the edit mode
Edit stuff
Press Esc to finish edit mode and toggle the command mode
Press/type : to indicate you want to type a command
Type and enter wq to save the changes and exit


If you want to delete all your commit history but keep the code in its current state, please use the following:

Checkout
git checkout --orphan latest_branch

Add all the files
git add -A

Commit the changes
git commit -am "commit message"

Delete the branch
git branch -D master

Rename the current branch to master
git branch -m master

Finally, force update your repository
git push -f origin master

Wednesday, September 19, 2018

Outlook Duplicate Calendar Entries

use the following command to reset the calendar pane

outlook.exe /resetnavpane