Hey! You feel frustrating to want to learn easily and quickly about Docker and don't reach it? And you think what learn Docker with ASP.NET Core is harder? Stop that, no more!
This post enums a lot of steps to make a Docker container in Windows contains an own ASP.NET Core application.
Prerequisites
If you are using Windows like me, you must:
- Install Docker Desktop for Windows (login could be required). Is necessary virtualization features enabled in the BIOS? If you don't enable them don't worry, the Docker setup can this for you.
- Install (or upgrade) Visual Studio, at least 2019.
Why don't install a lower version? Because in this version Microsoft add Docker support and works fine.
Starting with an existent solution
Note: If you haven't an existent solution, you can create any solution in Visual Studio, with ASP.NET Core any project as a unique requirement.
You can try with any solution, but only testing purposes, I use my example with a WebAPI in ASP.NET Core, and select the Api
project as StartUp Project.
After that, you need to make right-click in the same project and select Add > Docker Support…
Note: You must Docker Desktop running.
Step by step
- Setting the API project (WebAPI) as the StartUp project.
- Select the option "Docker Support" to create a Dockerfile.
- After, you select a target. You will select "Windows" and confirm that dialog.
Congrats! You have a Dockerfile (and .dockerignore
) into your StartUp project. But… no! It isn't a file ready to dockerize.
What I need do to dockerize?
First, take care. In the Dockerfile, I see this in the first lines: EXPOSE 80
. Now, only you can modify to see EXPOSE 1811
(port specified to launch the current API).
In the tools bar, you can see a "Docker" button instead of "IIS Express" or simply "Run". You only click in this button, and wait to debug.
When it finished, you can see the WebAPI into your navigator (if you don't configure this yet) at 10000 port
. It works!
Troubleshooting
-
Visual Studio error: "Can not find docker container"
You can delete the hidden
.vs
folder, and retry. If you don't see this folder, please enable the option "Hidden items" into Windows Explorer and now you see that folder.
And, if you suggest an enhancement, please contact me! ;)
(Versión en español disponible en Medium)
Top comments (3)
Thanks for this succinct yet informative article Roberto! Going to give this a shot when I have some down time.
Docker + Windows? It is not something I would choose.
And It's fine!
However, you can choose any OS or distribution to work with Docker.
But, if you need work with Docker and Windows 10, you have here a quick tutorial to make it possible 😉.