2

Im working with Microsoft Dynamics 365 Business Central. (ERP Software).

Im attempting to create build agents on my local server to set up Continious Integration with my projects.

On the buildserver i am running Docker Enterprise on Windows 2019.

When i spin up my dockeragent to facilitate the builds im experiencing an issue.

The dockeragent is asked by my CI flow to spin up another docker container called navcontainerhelper which is basically a docker container that contains the Business Central environment to build my application on.

However the navcontainerhelper doesnt know the docker commands since it doesnt include docker.

Ive researched and found that mounting the docker socket with -v is the way to do this however i cant seem to get that working.

When i create the agent i am using the following command:

docker run -v /var/run/docker.sock:/var/run/docker.sock -ti dockeragent:latest -e AZP_URL=<My azure url> -e AZP_TOKEN=<my azure token) -e AZP_AGENT_NAME=<my builder agent name>

when i attempt to execute this i get the following command which leads me to the mentioned conclusion.

docker : C:\Program Files\docker\docker.exe: Error response from daemon: invalid volume specification: '/var/run/docker.sock:/var/run/docker.sock'.
At C:\dockeragent\StartAgents.ps1:1 char:1
+ docker run -v /var/run/docker.sock:/var/run/docker.sock -ti dockerage ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (C:\Program File...n/docker.sock'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

See 'C:\Program Files\docker\docker.exe run --help'.

Could someone give me a pointer as to what i am doing wrong?

I have changed the script to use the named pipes instead for windows. it now mounts like this:

docker run -e AZP_URL=<My azure url> -e AZP_TOKEN=<my azure token) -e AZP_AGENT_NAME=<my builder agent name> -v \\.\pipe\docker_engine:\\.\pipe\docker_engine dockeragent:latest

However the container still refuses to recognize my docker command:

New-NavContainer : The term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable 
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\azp\agent\_work\***\s\scripts\Create-Container.ps***:36 char:***
+ New-NavContainer @parameters `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (docker:String) [New-NavContainer], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,New-NavContainer

PowerShell exited with code '***'.

Any pointers would be greatly appreciated!

AronChan
  • 245
  • 3
  • 19
  • i think they are using named pipes for windows? – 4c74356b41 Jul 20 '19 at 09:49
  • Your build server is windows 2019, but this path /var/run/docker is used for linux. Using windows path instead. – starian chen-MSFT Jul 22 '19 at 12:29
  • @4c74356b41 Using named pipes seems to be the correct approach. I just cant get it working. Currently im trying to mount it like this -v \.\pipe\docker_engine:\\.\pipe\docker_engine. The initial image spins up perfectly fine but when the yaml file of my CI integration attempts to run docker commands inside the container it claims that the container doesnt know the command "docker" – AronChan Jul 24 '19 at 14:29
  • 1
    well, this means you dont have the docker client\cli in the container, quite obvious – 4c74356b41 Jul 24 '19 at 14:36
  • @4c74356b41 But isnt that what the pipe does. It allows access to use the root docker from the system running the container? or am i completely mistaken? – AronChan Jul 24 '19 at 14:38
  • 1
    no, it just forwards that pipe\socket to your container. container still needs the binary to talk to docker engine. – 4c74356b41 Jul 24 '19 at 14:44

2 Answers2

3

in this case the answer was to use the named pipes like so:

-v \.\pipe\docker_engine:\\.\pipe\docker_engine

and to install the docker client into the container so it can talk to the docker engine

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • I tried installing the Docker Enterprise manually inside the buildagent container by using powershell commands. Its still not recognizing the docker command even though the container seemed to respond that the install was succesful – AronChan Jul 30 '19 at 07:40
  • When i run the "docker ps" command it shows me all the current containers on the host system. I assume this is related to the named pipe? – AronChan Jul 30 '19 at 07:40
  • Whats weird is that when the build agent attempts to run the docker container to build my software inside the agent container it claims that it doesnt recognize the docker command. – AronChan Jul 30 '19 at 10:25
0

I was having trouble with the install, so I used one of the docker provided windows images from docker hub as my base image instead of a microsoft one. Followed the remained of the microsoft instructions. Started the container with the below command and everything worked smoothly.

`docker run --env-file agent.env -v \\.\pipe\docker_engine:\\.\pipe\docker_engine --name dockeragent dockeragent:latest` 
MikeF
  • 764
  • 9
  • 26