12

In vs2019, I generate the docker image in the output window, the original command to generate the image was:

docker build -f "e:\work\dotnetcoreproject\rookie.qwt\rookie.qwt.webapi\dockerfile" --force-rm -t rookieqwtwebapi --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=rookie.Qwt.WebApi" "e:\work\dotnetcoreproject\rookie.qwt"

I want to change the image name rookieqwtwebapi to registry.rookie.qwt.webapi, how can I do it in vs2019?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
pepperann
  • 139
  • 1
  • 3
  • Is that a command you wrote yourself, or is this something generated by Visual Studio? i.e. you don't just want to know how to change the command, you want to know where to configure VS to change the command it's generating? – Rup Jan 13 '20 at 11:35
  • I doubt what you are trying to do has anything to do with VS. – Benjamin Jan 13 '20 at 11:35

3 Answers3

30

I want to change the image name rookieqwtwebapi to registry.rookie.qwt.webapi, how can I do it in vs2019?

According to the Microsoft's docs, there's a parameter of DockerfileTag for this purpose:

The tag that will be used when building the Docker image. In debugging, a ":dev" is appended to the tag.

So do it as below:

  1. Double click your project name in Solution Explorer
  2. Edit the project file, add a custom <DockerfileTag/>:
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UserSecretsId>65be249c-09e1-45ea-bac9-45d1cb4c82b6</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileTag>registry.rookie.qwt.webapi</DockerfileTag>
  </PropertyGroup>

Now VS will build the image with this tag of registry.rookie.qwt.webapi (or registry.rookie.qwt.webapi:dev when debugging) automatically .

itminus
  • 23,772
  • 2
  • 53
  • 88
  • Good find. And a Release build yields the _latest_ tag. Not obvious the _DevicefileTag_ property affects the repo name. – bvj Mar 26 '20 at 07:39
  • 4
    You can also use -t registry.rookie.qwt.webapi to generate an image with a custom name. – Alvaroma Jan 06 '21 at 15:24
  • I tried to use DockerfileTag but it seems is not changing my image name in the Azure Container Registry. It works fine locally and if I debug my application I see the correct image name in my local docker, but when publish on azure it continues to use the default name...any idea? – TheFedex87 Jan 02 '23 at 22:29
3

Go to the Properties of the project and change the Assembly name. It will change the entire image name. Image tag can be added in Publish Profile.

-1

Use the --tag or -t shorthand to add a custom name for docker image. You can also add the tag with the image name. More info here - https://docs.docker.com/engine/reference/commandline/build/

Run this command to see the image name:

docker build -t registry.rookie.qwt.webapi -f "e:\work\dotnetcoreproject\rookie.qwt\rookie.qwt.webapi\dockerfile" --force-rm   --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=rookie.Qwt.WebApi" "e:\work\dotnetcoreproject\rookie.qwt" 
Sahil Sharma
  • 1,813
  • 1
  • 16
  • 37
  • 2
    thanks,i know the docker build command ,but i want to know how to config docker build command in vs2019 – pepperann Jan 13 '20 at 12:13
  • I don't understand the relation between docker command and visual studio. You can either execute the docker command using .Net CLI or use the docker-compose.yml file for it. – Sahil Sharma Jan 13 '20 at 12:19
  • This is exactly what I was looking for, and makes the most sense. You shouldn't have to change the assembly name constantly for creating different images as the other people had recommended. What if I want a {projectname}-debug {projectname}-testing version? This works perfectly, thanks. – Kevin B Burns Feb 24 '21 at 17:22