https://github.com/fritzthecat9/dockercomposetest
Deploy two C# web APIs to Raspberry Pi with Docker Compose file
https://github.com/fritzthecat9/dockercomposetest
api c-sharp csharp docker docker-compose http https minimal-api raspberry-pi raspberry-pi-4 raspberry-pi4
Last synced: 2 months ago
JSON representation
Deploy two C# web APIs to Raspberry Pi with Docker Compose file
- Host: GitHub
- URL: https://github.com/fritzthecat9/dockercomposetest
- Owner: FritzTheCat9
- Created: 2024-04-24T19:22:15.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-27T12:47:41.000Z (almost 2 years ago)
- Last Synced: 2025-12-19T21:22:13.803Z (4 months ago)
- Topics: api, c-sharp, csharp, docker, docker-compose, http, https, minimal-api, raspberry-pi, raspberry-pi-4, raspberry-pi4
- Language: Dockerfile
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Docker compose:
This repository contains two C# web APIs served in single docker-compose file.\
You can run this two APIs on docker on windows with windows environment varaibles: "windows.env".\
You can run this two APIs on docker on Raspberry Pi with linux environment varaibles: "linux.env".
The README.md file contains commands that will allow you to:
- create images of your APIs depending on picked system and environment variables
- add the images to the docker hub platform
- download the images to the Linux (Raspberry Pi) / Windows
- run the all APIs containers on the Linux (Raspberry Pi) / Windows
### Api 1 (dockercomposetest_api):
```
http://localhost:5000
https://localhost:5001
```
### Api 1 (dockercomposetest_api2):
```
http://localhost:5002
https://localhost:5003
```
### Working certs (generate certificates then copy to raspberry pi, for https):
```
dotnet dev-certs https --clean
dotnet dev-certs https -ep $HOME\.aspnet\https\aspnetapp.pfx -p password
dotnet dev-certs https --trust
-ep - path to existing certificate file (.pfx) that you want to use for HTTPS development (existing PFX file)
```
##### IMPORTANT - COPY CERTIFICATE TO RASPBERRY PI!!! (use scp) -> to: $HOME/.aspnet/https (change to correct Raspberry Pi ip)
```
scp C:\Users\bartl\.aspnet\https\aspnetapp.pfx malinka@:/home/malinka/Desktop
ssh malinka@
sudo mv /home/malinka/Desktop/aspnetapp.pfx /home/malinka/.aspnet/https
```
### Build and up all containers (change environment variables depending on system You want to use):
```
docker-compose --env-file linux.env up -d --build
docker-compose --env-file windows.env up -d --build
--env-file - environment variables (other for different configuration / system)
-d - detached mode (services in the background, without blocking the command prompt)
--build - rebuild the docker images
```
### Docker compose up (create and start all containers)
```
docker-compose --env-file linux.env up -d
docker-compose --env-file windows.env up -d
```
### Stop / start Docker compose (only start or stop all containers)
```
docker-compose --env-file linux.env stop
docker-compose --env-file linux.env start
docker-compose --env-file windows.env stop
docker-compose --env-file windows.env start
```
### Docker compose down (stop and remove all containers)
```
docker-compose --env-file linux.env down
docker-compose --env-file windows.env down
```
### Docker compose push (push all containers to docker hub)
```
docker-compose --env-file linux.env push
docker-compose --env-file windows.env push
```
### Install Docker Compose on Raspberry Pi:
```
sudo apt install docker-compose
```
### Copy files to Raspberry Pi (change to correct Raspberry Pi ip)
- Copy "docker-compose.yml" file to Raspberry Pi (using scp)
- Copy "linux.env" file to Raspberry Pi (using scp)
```
scp C:\Users\bartl\source\repos\DockerComposeTest\docker-compose.yml malinka@:/home/malinka/Desktop/
scp C:\Users\bartl\source\repos\DockerComposeTest\linux.env malinka@:/home/malinka/Desktop/
```
### Pull and run Docker Compose on Rapberry Pi / Windows:
```
docker-compose --env-file linux.env pull
docker-compose --env-file linux.env up -d
docker-compose --env-file windows.env pull
docker-compose --env-file windows.env up -d
```
### Check docker images and containers:
```
docker images
docker ps -a
```
### Test Apis:
```
curl http://localhost:5000/api
curl -k https://localhost:5001/api
curl http://localhost:5002/api
curl -k https://localhost:5003/api
-k - ignore certificate check
```
### Pull only single image if needed
```
docker pull fritzthecat9/dockercomposetest_api:LINUX
docker pull fritzthecat9/dockercomposetest_api2:LINUX
docker pull fritzthecat9/dockercomposetest_api:WINDOWS
docker pull fritzthecat9/dockercomposetest_api2:WINDOWS
```
### Container logs
```
docker logs container_name_or_id
-f - continuously follow or stream the logs generated by a Docker container
docker logs -f container_name_or_id
```