A simple .NET API running inside a Docker container.
- Build the Docker image:
docker build -t dockerized-dotnetapi . - Run the Docker container:
docker run -d -p 2501:80 --name mydockerapi-container dockerized-dotnetapi
- Access the API:
- Open your browser and go to: http://localhost:2501
- For environment check, visit: http://localhost:2501/env
- Start the container:
docker-compose up -d
- Stop and remove containers:
docker-compose down
- Rebuild the image (if changes are made):
docker-compose up --build -d
- Access the API:
- Open your browser and go to: http://localhost:2501
- For environment check, visit: http://localhost:2501/env
By default, the API runs in Production mode inside the Docker container.
You can override this setting by passing an environment variable when running the container:
docker run -d -p 2501:80 -e ASPNETCORE_ENVIRONMENT=Development --name mydockerapi-container dockerized-dotnetapiTo verify the environment mode, open:
The application logs startup events into a file inside the container:
- Logs are stored in
/app/logs/log.txt. - If the directory does not exist, it is created automatically.
Dockerized-DotNetAPI/
│-- Dockerfile
│-- docker-compose.yml
│-- Dockerized-DotNetAPI.csproj
│-- Program.cs
│-- logs/ (generated at runtime)
- This project demonstrates a basic .NET API inside a Docker container.
- Supports both Docker CLI and Docker Compose for running the application.
- Ensure Docker is installed and running before executing the commands.
- Includes basic logging to track application startup.