Docker Tools for Visual Studio (Preview) Build Tag Errors

I just recently started exploring Docker Tools for Visual Studio Tools 2015 – Preview and wanted to post an usual issue I ran into in case anyone else comes across it.  The issue has to do with a problem using a VS Project Name that contains special characters.

  

Troubleshooting The Tag Error


I started a brand new project using the WebAPI .NET Core template and named my project POC.Docker.HelloAzureContainer (note my choice to use a fully qualified name as this part will come up later).  Shortly after attempting to build the new project I landed at the following:

aafeedfsesfesfd4189e156fe

“The command “powershell -ExecutionPolicy RemoteSigned .\Docker\DockerTask.ps1 -Build -Environment Release -Machine ‘default’ -ClrDebugVersion VS2015U2″ exited with code 1.”

This didn’t do me much help other than point me to where the issue eventually bubbled up to.  I decided to venture into the Build Output window and found the underlying cause:

1>  Error response from daemon: no such id: poc.docker.helloazurecontainer_poc.docker.helloazurecontainer
1>  Build : Failed to tag the image
1>  At C:\Users\cmyers\Dev\POC\POC.Docker.HelloAzureContainer\src\POC.Docker.HelloAzureContainer\Docker\DockerTask.ps1:43
1>  4
1>  char:5
1>  +     Build
1>  +     ~~~~~
1>      + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
1>      + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Build

 

At this point, I decided to take a look at the DockerTask.ps1 file to track down what was occurring behind the scenes.  I eventually landed myself around line 243 where it would appear the error was getting thrown.

cmd /c docker-compose -f $composeFileName -p $ProjectName up -d "2>&1"
if ($? -eq $False) {
	Write-Error "Failed to build the images"
}

After debugging the script, I found that the $composeFileName was “poc.docker.helloazurecontainer_poc.docker.helloazurecontainer”.  However, Docker was reporting me that there was no image with that name:

cmyers@localhost ~
$ docker images
REPOSITORY                                                    			TAG                 IMAGE ID            CREATED             SIZE
pocdockerhelloazurecontainer_poc.docker.helloazurecontainer   	latest              92e7b890102b        4 minutes ago       251.7 MB
microsoft/dotnet                                              			1.0.0-rc2-core      0020657f581c        2 days ago          242.3 MB

 

You can probably see now why I mentioned earlier that I should not have used a fully-qualified name for my project.  Had I not done so, I would not have run into this issue.

 

Fixing the Problem


From what I’ve gathered through debugging and trying the various commands in the PowerShell file manually, it would seem that the docker-compose command removes all special characters that are provided for the ProjectName parameter.

To fix this, I changed the DockerTask.ps1 file that gets generated when you “Add Docker Support” to your project.

Around lines 130 through line 131 (at the time of writing this post), you will find:

# Calculate the name of the image created by the compose file
$ImageName = "${ProjectName}_poc.docker.helloazurecontainer"

 

To work around the issue I found, I modified that section to the following:

#HOTFIX: docker-compose appears to be removing special characters from project name
$ComposeProjectName = $ProjectName.Replace(".", "")

# Calculate the name of the image created by the compose file
$ImageName = "${ComposeProjectName}_poc.docker.helloazurecontainer"

 

This fix seems a bit hackish, and there may be a better way around this.  However, this got me past the issue I was seeing and back to exploring, which was my original intent.

If it is of help to anyone, I am currently using Docker version 1.11.1, build 5604cbe on Windows.

Tags: , , , ,

Reader's Comments »

  1. […] that using fully qualified namespaces in your Docker project name can cause some issues.  See this post for more […]

  2. […] that using fully qualified namespaces in your Docker project name can cause some issues.  See this post for more […]

Leave a Reply