I'm working on my first Docker container for a .NET ASP Core Web API project called TravelBridgeAPI. My team is using it for a school project, but I'm having trouble setting up the Dockerfile. I wrote a GitHub Actions script that logs into Docker Hub and attempts to build the container, but it keeps getting stuck while trying to find my csproj file. I'm developing this on Windows 11 using Visual Studio 2022. Here's what my Dockerfile looks like:
1. I'm using a Windows-based container as the base.
2. I specify the working directory and expose ports 80 and 443.
3. In the build stage, I try to copy TravelBridgeAPI.csproj and run a restore command, but it's not working.
4. Then, I copy the rest of the files and run the build command.
5. For the final container, I copy the output from the publish phase.
Any advice on what I'm doing wrong?
4 Answers
You might want to check your path separators. Windows containers sometimes require backslashes instead of slashes. Also, your image version is a bit outdated; maybe try using a more recent SDK like 9.0.
It sounds like the issue might stem from using Windows containers. A lot of the Docker ecosystem is Linux-based, so you might be making things more complicated than they need to be. Consider transitioning to Linux containers if you can. It's generally recommended for better compatibility with Docker.
Honestly, I don't think Windows images are the best choice here. If you're serious about getting to grips with Docker, it’s usually better to go with Linux containers. They just work better in most setups and save you a lot of hassle.
I was in the same boat with Docker Desktop and WSL. Windows Pro can be restrictive. If you're having so many issues, maybe switching to VirtualBox could simplify things for you. Just my two cents!
Yeah, I get that! I might give Linux containers a shot since it seems like a common issue.