Visual Studio 2022 push to custom docker container stopped working after changing image name

762 Views Asked by At

I have a visual studio .pubxml for publish into a custom docker container with a dockerfile.

It's working well, the build generates the image and then the push is done correctly.

The problem is that I need to change the image name to push, by default it takes the project name.

<Project>
<PropertyGroup>
    <WebPublishMethod>Custom</WebPublishMethod>
    <DockerPublish>true</DockerPublish>
    <RegistryUrl>https://myUrl</RegistryUrl>
    <UserName>XXXXX</UserName>
    <PublishImageTag>latest</PublishImageTag>
    <PublishProvider>ContainerRegistry</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <_TargetId>DockerCustomContainerRegistry</_TargetId>
    <!--<DockerfileBuildArguments>-t NEWNAME</DockerfileBuildArguments>-->
    <DockerfileTag>NEWNAME</DockerfileTag>
</PropertyGroup>

This is my .pubxml, with the DockerfileBuildArguments -t NEWNAME or with the DockerfileTag NEWNAME. The image that is generated is correct. But when visual studio try to do the push is still searching for the old named image (that is not generated now)

docker push PROJECTNAME:latest

But I want visual studio to do

docker push NEWNAME:latest

and I'm getting this error cause the image with the PROJECTNAME is not generated now:

Microsoft.WebTools.Azure.Publish.Docker.DockerCommandException: Running the docker.exe tag command failed.
Error response from daemon: No such image: PROJECTNAME:latest

Any ideas of how I can change that?

Thanks!

2

There are 2 best solutions below

4
Nathan Carlson - MSFT On

<DockerfileTag>NEWNAME</DockerfileTag> needs to go into the project file not the publish profile.

0
Nothing On

you can do it like this

edit Docker Compose

The docker-compose.yml file references the name of the image that's created when the project runs:

version: '3.4'

services:
  hellodockertools:
    image: ${DOCKER_REGISTRY}NEWNAME
    build:
      context: .
      dockerfile: HelloDockerTools/Dockerfile

The NEWNAME:latest image is generated when the app runs in Release mode.

enter image description here

the docs

https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/visual-studio-tools-for-docker?view=aspnetcore-2.1