Docker + Visual Studio – resolving error – Publish has encountered an error. Docker support must be enabled in the project

Publishing .NET Core application from Visual Studio to Docker Registry - Error - Publish has encountered an error. Docker support must be enabled in the project
Publishing .NET Core application from Visual Studio to Docker Registry - Error - Publish has encountered an error. Docker support must be enabled in the project

Background / Scenario :

  1. We have our docker team developing containerised applications (docker images)
  2. Our docker team needs to be push those respective docker images to our private registry (I am covering Docker Registry concepts in detail in upcoming articles)
  3. So got an opportunity to demonstrate how to push our application / docker image to our private registry from Visual Studio
  4. While publishing my application to our private registry from Visual Studio got below error

Error / Issue :

Publish has encountered an error.
Docker support must be enabled in the project. See https://aka.ms/vs-add-docker for information on adding Docker support to the project.

Publishing .NET Core application from Visual Studio to Docker Registry - Error - Publish has encountered an error. Docker support must be enabled in the project
fig : Publishing .NET Core application from Visual Studio to Docker Registry – Error – Publish has encountered an error. Docker support must be enabled in the project

Details :

  • I am using my Visual Studio 22 preview – community edition
  • I have created simple one .NET Core console application to demonstrate as
Simple .NET Core console application - will publish as Docker Image to private docker container registry
fig : Simple .NET Core console application – will publish as Docker Image to private docker container registry
  • We want to publish this application to our private docker container registry
  • So in “Solution Explorer” right click on project and “Publish” as
fig : Publishing .NET Core console application
  • On click on of “Publish” we will get an “Publish” dialog and various options to publish as
fig : Publishing .NET Core console application to Docker Container Registry
  • Select the target – “Docker Container Registry” and click on “Next” button on the bottom of “Publish” dialog
  • Then we need to select the – “Specific target” as shown in below fig
Publishing .NET Core console application to Docker Container Registry
fig : Publishing .NET Core console application to Docker Container Registry
  • Here we will select an option – “Other Docker Container Registry” option
  • Click on “Next” button, we will have an option for our private registry URL and image tag
  • Please specify the URL of registry and image tag
  • Once we specified respective details, please click on “Publish” button as
Publishing .NET Core console application to Docker Container Registry - Getting error - "Publish has encountered an error"
fig : Publishing .NET Core console application to Docker Container Registry – Getting error – “Publish has encountered an error”

Solution :

  • By default Docker support is not added to Visual Studio project
  • We need to explicitly add the docker support to our Visual Studio project

Steps to add Docker support the Visual Studio project :

  • In Visual Studio , Solution Explorer, right click on project and click on “Add” as
Docker - Adding Docker support to Visual Studio
fig : Docker – Adding Docker support to Visual Studio
  • From “Add” option select option – “Docker Support” as
Docker - Adding Docker support to Visual Studio
fig : Docker – Adding Docker support to Visual Studio
  • As we click on “Docker Support…” option we will get an “Docker File Options” to select the our OS as
Docker File Options dialog - selecting target OS
fig : Docker File Options dialog – selecting target OS
  • As we select our OS, “DockerFile” is added to our project as (I’ll explain in detail about DockerFile in separate article)
After adding "Docker Support" to Visual Studio - Docker File is added to our Visual Studio project
fig : After adding “Docker Support” to Visual Studio – Docker File is added to our Visual Studio project
  • Now please try to publish and project will published to our private contained registry successfully 🙂

We have very good articles for Docker and Kubernetes please have a look once – https://knowledge-junction.com/category/containerization/

Thanks for reading 🙂 If its worth for you , kindly please Like and Share

HAVE a GREAT TIME AHEAD 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: