Solutions
Markets
References
Services
Company
Create a NAV Windows/Docker container image with one command

Create a NAV Windows/Docker container image with one command

21. February 2017

Create a NAV Windows/Docker container image with one command

I previously wrote about NAV 2017 in a Windows Container where I just managed to get NAV 2017 up and running. Some days ago Jakub Vaňák contacted me with a detail question about that post and told me that he managed to create a Dockerfile for NAV Server instances. What that means (and really kudos to Jakub as he did about 99% of the work) is that you don’t need to jump through all the hoops and type all the stuff that I did but really can create your container image with a single command!

Preparation

Ok, there are some preparations: First, you need to get the code from Jakub’s GitHub repobut as probably all of you know, who even remotely followed the exciting news about the new NAV dev environment aka Visual Studio Code, that is rather easy: Open VS Code and just clone the repository through the friendly new welcome screen. If you open the file called “Dockerfile” VS Code actually recommends to download the corresponding extension. This takes about ten seconds and a restart of VS Code and you have full language support including IntelliSense and all the other goodies for Docker! I know I mentioned this before, but I really like VS Code and the NAV team’s decision to use it as the future dev environment for NAV.

As a second preparation you need to download a NAV installation DVD like NAV 2017 CU3 (I used the DE version), extract it and put the files in the “content” folder inside the directory structure you got from GitHub. Of course you also need to setup Docker (check the post mentioned above for info about that) and a SQL Server with a database you’ll use. I just fired up a SQL Server container and restored the Cronus DB from CU3 (also described in the post above).

Ready to go

Now we are ready: Just open the terminal of your choice (in my case I used the one integrated in VS Code) and start _rebuild.bat. This will take some minutes and show you progress information, but in the end you will have an image for NAV with the build you just downloaded. You can run “docker images” to show you the available images which in my case returns

REPOSITORY TAG IMAGE ID CREATED SIZE
myprivaterepo/navservice 10.0.15140.0 4c57ef77cc5c 29 seconds ago 15.6 GB

As you can see it automatically gets the build information from the DVD and tags the image accordingly. If you use another build, you get the same image but with another tag which is exactly how Docker images usually work. Again, kodus to Jakub! Now I would push this to my repository so that my colleagues or customers can also use the image, but I skip those steps as for testing purposes it also works locally.

We have the image ready, now we can start it. For that we have multiple scripts, but we need to tell it where to look for the database, which user to use etc.. I like to see what is happening in the running container at least for testing, so I use _run.interactive.params.bat but need to add the actual values in there. In my case it looks like this:

docker run -ti --rm --hostname=NAVSERVER -p 7045-7048:7045-7048 -e "sql_server=172.24.42.93" -e "sql_db=Cronus2017CU03" -e "sql_user=sa" -e "sql_pwd=VerySecret*123" -e "nav_user=DefaultUser" -e "nav_user_pwd=VerySecret*" -e "import_cronus_license=false" -e "config_instance=$True" --name %ContainerName% %host%/%ImageName%

As a result you see how the instance gets configured, the user optionally gets created and in the end you have a running NAV Server instance inside a Windows Server 2016 Core. I can now start my Windows Client and connect it to the NAV server instance (with some additional Client tweaking because of the self-signed cert, again see my original post). Just amazing!

Done. And now?

The first question is, why would you do this? I answered some of it in the last post but again, some interesting scenarios:

I could go on with some variations on the same topic but I guess you can see the benefits (if you have on or more of those problems). The second question is, how to further improve this? The next step now would be to create a Docker Compose file which allows us to create multi-container environments. With that we could e.g. create an environment with 1 SQL Server container, 1 NAV Server container and 1 IIS container to just start a whole NAV environment with 1 command. And then we could take it a step further and use one of the orchestration tools like Docker Swarm or Kubernetes or Mesos to build a scalable cluster (as far as SQL and NAV allow it).

The only issue now is that Microsoft doesn’t officially support it but maybe they will look into this. I really think we would have awesome new possibilities and a lot easier life for NAV admins and hosters.

Last but not least, thanks a lot to Jakub for coming up with almost everything of the code and sharing it!

To be continued…


7 Kommentare zu “Create a NAV Windows/Docker container image with one command”

  1. Hi Tobias,

    thanks for sharing this post as I can find it very helpful for docker-unfamiliar NAV users.

    Many thanks for your help, willingness to help and time dedicated to the problem you solved. Without those aspects, I wouldn`t succeed. Thanks also for your contributions you have made later…

    Best Regards,
    Jakub

    1. Hi Jakub,
      thanks for the tooling. I just attended one WUG in Brno about containers and I started to understand these things.

      BUT one thing for Tobias: the containers are good for DevOps, not for using for customers. Mainly because security. Do not forget that the processes are sharing the windows core, thus there is possibility to break through the processes to other containers etc. I now that it is not so big problem for NAV or development environment, but if you take the security seriously and you want to have secure environment for your customers financial data, the containers are not good for that.

      Kamil

      1. Hi Kamil,

        ok, I get that, but coming from either a single-tenant environment with multiple instances (one for each customer) or even from a multi-tenant environment I don’t see why multiple containers running on a machine would be worse. If you are coming from an environment where every customer has it’s own seperate VM, ok, but not in the other scenarios. Or am I missing something here?

        Tobias

  2. Hi Kamil,
    you are welcome 🙂 And nice to have your support.

    My intention actually is just DevOps but I can see the container technology can be deployed in PRO as well. Of course, there are pure security concerns like the credential bypass between the host and container etc.

    And about the core and sharing its resources via namespaces – you are right but there is still –isolation flag and you can switch to “hyperv” which will create real VM for each container. You loose some advantages (resource sharing) but some of them are still there… And you can forget at least some of the concerns.

    When working with the data that will need some securities you should, of course consider the infrastructure and start using Docker Swarm or Kubernetees etc. And deploy something like hashicorp vault etc. This will help you to overcome those issues and you are free. Or you can still use gMSA but this can not confirm as we are preparing for that now…

    Regards,
    Jakub

  3. Hello Tobias,
    thank you for your great article.
    We are new in the docker world and since NAV 2018 CU5 it is not possible to work with multible RTC- and CSIDE-Clients, so docker is our only chance 🙂
    Is there a script or documentation like yours but to build easy a CU with a NAV-Docker Client direct on my PC?

    1. Hello Andreas,

      this actually is a quite old post from almost two years ago when we didn’t have official images from Microsoft. Now we have them and the approach should be very different. What exactly are you trying to do?

  4. Das kann ich besser auf Deutsch versuchen zu erklären wenn das OK ist 🙂
    Ab NAV2018 CU5 bis aktuelle NAV365 Version ist es leider nicht mehr möglich einfach eine NAV-Installation zu clonen und mit den aktuellen CU-Dateien zu überspielen und die Clients zu starten (Der Dienst funktioniert).
    Wenn man die Configdateien löscht kann man den RTC-Client wieder starten, aber die Entwicklungsumgebung funktioniert nicht sauber (stürzt z.B. ab wenn man in CodeUnit auf Design klickt). Bis jetzt konnte Microsoft uns da auch nicht helfen, da das auch kein offizieller Weg wäre. (War für uns und manch anderer Microsoft Partner aber eine sehr gute Lösung wenn man viele unterschiedliche Versionen zum Entwickeln benötigt)
    Daher war die Überlegung mit Docker zu arbeiten. Aber da sind wir noch am Anfang und probieren sehr viel mit unterschiedlichen Scripten, aber bisher konnten wir noch kein gutes Tutorial / Script finden was uns die Sache vereinfacht :-/


Leave a Reply