2

I have a typical .NETCore WebAPI project structure:

TestApi
  |--- src
    |--- TestApi.Domain
    |--- TestApi.Infrastructure
    |--- TestApi.WebApi
      |--- TestApi.WebApi.csproj <--- Startup project
  |--- tests
  |--- TestApi.sln

Where should I put my Dockerfile file? I thought that convention is to put it on the same level as TestApi.WebApi.csproj (main project), but how can I COPY Domain and Infrastructure projects along with?

Can Dockerfile be created on the .sln level? Is it a good practice?

Thanks!

1
  • You can create files in the solution folder if you want. Then add them manually into the solution. But since WebApi is the project that is running it makes sense to create your Dockerfile in your WebApi project Commented Jun 23, 2020 at 23:40

1 Answer 1

1

Much depends on your specific situation so it is difficult to provide an exact recommendation.

In short, including the Dockerfile at the .sln level, or even at the root of your source repository, is acceptable. As a general practice, most developers that work with docker prefer to keep the Dockerfile in the working directory for the docker build context. I recommend you read the following guidelines on docker build:

https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#understand-build-context

Your build can use a COPY instruction to reference a file in the context. Therefore, if you want to COPY multiple projects from your solution into your image during docker build, then you should save the Dockerfile in a parent directory that contains all projects which need to be included.

You might benefit from this dotnet docker sample repository on github to give you some ideas about the structure of your repo:

https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetapp

I also recommend that you read about how to exclude files from your image using a .dockerignore. This will help you minimize your final image size.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.