Solutions
Markets
References
Services
Company
NAV on Docker with Portainer

NAV on Docker with Portainer

29. July 2017

NAV on Docker with Portainer

When you get used to it, working with the CLI for Docker / Windows Containers is quite easy but having a GUI is more convenient, especially for newcomers. A very good GUI for Docker / Windows Containers is  Portainer, which is free and you can get services and support from the company behind it. I struggled for quite some time to get it up and running because a) the Docker community is still very Linux-dominated with Windows Containers being the newcomer and b) I had some trouble configuring the connection with our company proxy. Let me show you what needs to be done and how easy it is to get your NAV environment up and running with something like this as a result:

Networking

According to the Portainer documentation it should be possible to set an internal port proxy to access the Docker API from the Portainer Container like this

netsh interface portproxy add v4tov4 listenaddress=10.0.75.1 listenport=2375 connectaddress=127.0.0.1 connectport=2375
docker run -d -p 9000:9000 portainer/portainer -H tcp://10.0.75.1:2375

However I was unable to get this up and running1  and ended up doing the following which is a security problem as it makes the API available from your whole network, so you might not want to do that, but I didn’t find another way to get it done:

  1. Bind the API port to all IPs by changing C:\ProgramData\docker\config\daemon.json to
    {
        "hosts": ["tcp://0.0.0.0:2375", "npipe://"]
    }
    
  2. Create a transparent network which we will then use for the Portainer container
    docker network create -d transparent MyTransparentNetwork
    
  3. Run the Portainer container with
    docker run -d --network=MyTransparentNetwork --name portainer --hostname portainer portainer/portainer
    
  4. Open portainer at http://portainer:9000
  5. Enter [containerhost]:2375 as your endpoint

Not exactly straight forward but it might be easier for you if you don’t have a mandatory proxy and also this might be the last time you use the CLI… 🙂

Actually using Portainer

If you have come that far you now have a nice web interface to work with your containers. You can pull images, create new containers, see the status and log entries of running containers, manage them and even a get a session inside the container within your browser:

Now how about running NAV inside it? Microsoft is starting to work with Docker (actual scope not yet defined) as you might have noticed when checking the agendas for Directions EMEA and TechDays (Directions NA to follow)2, therefore I am in the following not using Jakub Vanak’s excellent repo as in previous posts but a private one by Freddy Kristiansen of Microsoft. But you can achieve the same with either your own Dockerfiles or Jakub’s.

You can manually enter the necessary parameters in the GUI or you can use my template definitions by entering https://raw.githubusercontent.com/tfenster/templates/nav-and-iis/templates.json through Settings > Use custom templates > URL. With that you get three new templates with two being of interest for this scope: One for a generic NAV image where you have to provide your own DVD, one for the current dev environment (keep in mind that this is a Container, so you still need to install and setup your client).

If you have those in place, it really is incredibly easy to get your dev environment up and running. I’ve shortened the wait times a bit as you can see if you look at the timestamps but still from intialization to being ready for connections it takes about half a minute and from selecting the template to being ready it takes approximately a minute:

Before you can login you need to enter the Container either through the session feature in Portainer or by entering a PowerShell session as described here and calling

net user <login> <password

You could do that in Portainer but as everyone with admin access could then read your password, you probably don’t want to do that.

I really like the new possibilites Docker / Windows Containers bring from a development as well as from a production / hosting standpoint and really am happy how the NAV team is among the “early adopters” inside Microsoft. Just think back three years and here we are now, running NAV in the Cloud as full SaaS solution and also having it inside Windows Containers. Microsoft from my point of view is really moving in the right direction!

  1. This might be connected with the problem that I had to add our company proxy to enable pulling images from the Internet. This can done with

    [Environment]::SetEnvironmentVariable(“HTTP_PROXY”, “http://ip:port, [EnvironmentVariableTarget]::Machine)

    where you need to make sure to set the Target to Machine as otherwise at least in my experience the Docker service won’t pick that setting up. I played with overwriting the HTTP_PROXY and NO_PROXY environment variables just for the Portainer container but couldn’t get it to work that way

  2. Freddy Kristiansen is hosting those sessions and even a workshop with Jakub Vanak and me, so drop by if you are at Directions EMEA or TechDays (I won’t be at NA)!

7 Kommentare zu “NAV on Docker with Portainer”

  1. Hi Tobias, great article!!!

    I have some recommendations or some small improvements:

    – In case you are running the container on a transparent network, you can map the internal port 9000 to the port 80 (usually this is no problem but depends on a specific application) like this “-e 80:9000”. Then you can access your Portainer instance via your hostname (if registered in DNS or via DHCP) or its IP, e.g. “http://myportainer”.

    – I would recommend using volumes to share internal “c:\data” folder with your host. It will help you to maintain the configurations. This approach is very useful, especially in case you use Portainer frequently and you want to stay up to date with the Portainer version and don`t want the reconfigure manually with each upgrade.

    – If running on swarm you can “easily” (actually this requires some preparations) start using Swarm Secrets.

    Templates are pretty useful, we run templates with the icons etc. in a tiny container (https://hub.docker.com/r/portainer/templates/). What I am missing here:

    – Is the possibility to specify the container tag dynamically. In case you want to maintain multiple NAV versions or language mutations you actually need to maintain multiple templates and this is not the best approach (for us).

    – Templates aren`t Swarm compatible yet (right now but looks that in the future will be).

    1. Sorry, the port mapping actually works only on “nat” network types. I have made this mess because I was using the port mapping when started experimenting with this tool. But for several months I have been using Portainer on the transparent network and in this case, you need to expose the port 80 (-e 80) explicitly and you have to override Portainer to run on the port 80 as well (-p ‘:80’). This parameter should be placed at the end of the docker run command:

      docker run -d -e 80 -v D:\DOCKER\_Configs\Portainer:C:\data –network transparent –restart=always –name portainer –hostname portainer portainer/portainer:windows-amd64 -p ‘:80’

      1. Hi Jakub,

        thanks for your feedback! I personally don’t mind running portainer on :9000 but thanks for the hint. And I’ve added the volume mapping which obviously makes a lot of sense.

        Regarding templates: I’ve created a small template which allows to run a IIS-based template Web Server so that you don’t need to have a Linux-based Container if you don’t want to: https://github.com/portainer/templates/pull/70

        The “dynamic tags on templates” idea is very interesting. The portainer maintainers are quite open and responsive, I’ve even add a first one-line change to allow setting the hostname to the same as the container name: https://github.com/portainer/portainer/pull/1084. Having dynamic tags in templates shouldn’t be that difficult

        1. I don`t mind running Linux containers. Actually, I am open to run Linux containers because there are several interesting use-cases you can`t run on Windows containers right now (for example VPN clients).

          And thanks a lot for PR you have made on Portainer GitHub repo.

  2. I have forgotten the data mapping example so here it is:
    -v D:\DOCKER\_Configs\Portainer:C:\data

    I also recommend (in case you mean it seriously with Portainer) using “–restart” policy flag (alway or unless-stopped).

  3. hi, trying to follow, but i get an error: No such image: navdocker.azurecr.io/dynamics-nav:devpreview.

    do i do something wrong?

    1. Maybe you didn’t login before pulling? But actually you don’t need to use the private repo at azurecr.io anymore as the NAV images including the devpreview are now publicly available, see here


Leave a Reply

Your email address will not be published. Required fields are marked *