Sure, here is a docker-compose.yml file for a .NET REST API:
version: "3.7"
services:
app:
image: my-app
container_name: my-app
ports:
- "80:80"
volumes:
- .:/app
environment:
- ASPNETCORE_ENVIRONMENT=Development
db:
image: postgres:12
container_name: my-db
volumes:
- ./data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=password
This docker-compose.yml file defines two services: app and db. The app service is a .NET REST API that is built using the microsoft/aspnetcore:3.1-aspnetcore-runtime image. The db service is a PostgreSQL database that is built using the postgres:12 image.
The app service is exposed on port 80, and the db service is exposed on port 5432. The app service mounts the current directory (.) to the /app directory in the container, and the db service mounts the ./data directory to the /var/lib/postgresql/data directory in the container.
The APPNETCORE_ENVIRONMENT environment variable is set to Development in the app service. This tells the .NET Core runtime to use the development configuration when running the application.
The POSTGRES_PASSWORD environment variable is set to password in the db service. This tells the PostgreSQL database to use the password password when connecting to the database.
To use this docker-compose.yml file, you can run the following command:
docker-compose up
This will create the two services and start them. You can then access the .NET REST API at http://localhost:80.