I want to publish docker image from VS2022 to GitHub ghcr.io registry, but I could not find a way to set a proper tag.
I have a simple ghcr.io.pubxml
:
<Project>
<PropertyGroup>
<WebPublishMethod>Custom</WebPublishMethod>
<DockerPublish>true</DockerPublish>
<RegistryUrl>https://ghcr.io</RegistryUrl>
<UserName>USERNAME</UserName>
<PublishImageTag>0.0.1</PublishImageTag>
<PublishProvider>ContainerRegistry</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<ProjectGuid>4c629800-XXXX-XXXX-XXXX-dd71619c5281</ProjectGuid>
<_TargetId>DockerCustomContainerRegistry</_TargetId>
</PropertyGroup>
</Project>
On publishing it builds the image as expected
build -f ".\Dockerfile" --force-rm -t assemblyname --build-arg "BUILD_CONFIGURATION=Release" --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=Assembly.Name" ".\src"
Note that it uses the assembly name as a tag. After building it set a new tag to the image
naming to docker.io/library/assemblyname done
Before publishing it change the tag to utilize the version and registry:
The push refers to repository [ghcr.io/assemblyname]
So the final tag is: ghcr.io/assemblyname:0.0.1
– which is an invalid tag for GitHub, it requires docker push ghcr.io/NAMESPACE/IMAGE_NAME:2.5
So I have a publishing error
Publish has encountered an error.
Running the docker.exe push command failed.
name invalid
A diagnostic log has been written to the following location:
...
There is a way to change the default tag. I added DockerfileTag
option to the project file:
<PropertyGroup>
<Version>0.0.1</Version>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileTag>xakpc-dev-labs/my-name</DockerfileTag>
</PropertyGroup>
The new tag is used in the build process as expected:
docker build -f ".\Dockerfile" --force-rm -t xakpc-dev-labs/my-name --build-arg "BUILD_CONFIGURATION=Release" --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=Assembly.Name" ".\src"
It creates an image with the tag docker.io/xakpc-dev-labs/my-name:latest
But then it tries to change the tag and fails with an error
Failed to push docker image
Publish has encountered an error.
Running the docker.exe tag command failed.
Error response from daemon: No such image: my-name:latest
A diagnostic log has been written to the following location:
...