https://github.com/fritzthecat9/dockertest
Deploy C# web API to Raspberry Pi with Docker
https://github.com/fritzthecat9/dockertest
api c-sharp csharp docker http https minimal-api raspberry-pi raspberry-pi-4
Last synced: 3 months ago
JSON representation
Deploy C# web API to Raspberry Pi with Docker
- Host: GitHub
- URL: https://github.com/fritzthecat9/dockertest
- Owner: FritzTheCat9
- Created: 2024-04-19T14:58:08.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-24T19:39:24.000Z (about 1 year ago)
- Last Synced: 2024-12-29T09:42:27.693Z (5 months ago)
- Topics: api, c-sharp, csharp, docker, http, https, minimal-api, raspberry-pi, raspberry-pi-4
- Language: C#
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Deploy C# web API to raspberry pi with docker
This repository contains C# web API code that provides one endpoint at the addresses (http://localhost:5000/weatherforecast, https://localhost:5001/weatherforecast).The README.md file contains commands that will allow you to:
- create an image of your API
- add the image to the docker hub platform
- download the image to the Raspberry Pi
- run the container with your web API on the Raspberry Pi### Build, Build for raspberry pi (for raspberry pi target platform "linux/arm64"):
```
docker build -t dockertest_api .
docker build -t dockertest_api --platform linux/arm64/v8 .
docker build --no-cache -t dockertest_api --platform=linux/arm/v7 .
docker build --no-cache -t dockertest_api --platform=linux/arm64/v8 .
docker build --no-cache -t dockertest_api --platform=linux/arm64 .
-t - name and tag of the image
```
### Rebuild (--no-cache):
```
docker build --no-cache -t dockertest_api .
```
### Working http:
```
docker run -d -p 5000:5000 -e ASPNETCORE_HTTP_PORTS=5000 -e ASPNETCORE_ENVIRONMENT=Development dockertest_api
```
### Working certs (generate certificates then copy to raspberry pi):
```
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/https/
```
### Working https:
```
docker run -d -p 5000:5000 -p 5001:5001 -e ASPNETCORE_URLS="https://+:5001;http://+:5000" -e ASPNETCORE_HTTP_PORTS=5000 -e ASPNETCORE_HTTPS_PORT=5001 -e ASPNETCORE_ENVIRONMENT=Development -e ASPNETCORE_Kestrel__Certificates__Default__Password=password -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v "$HOME/.aspnet/https:/https/" dockertest_api
```
### Other WRONG commands:
```
dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p password
docker run -d -p 5000:5000 -p 5001:5001 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTP_PORTS=5000 -e ASPNETCORE_HTTPS_PORT=5001 -e ASPNETCORE_Kestrel__Certificates__Default__Password=password -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v %USERPROFILE%\.aspnet\https:/https/ dockertest_api
docker run -d -p 5000:5000 -p 5001:5001 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTP_PORTS=5000 -e ASPNETCORE_HTTPS_PORT=5001 -e ASPNETCORE_Kestrel__Certificates__Default__Password=password -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v "$HOME/.aspnet/https:/https/" dockertest_api
```
### Tag your local image
```
docker tag dockertest_api fritzthecat9/dockertest_api:1.0
docker tag dockertest_api fritzthecat9/dockertest_api:latest
```
### Log in to Docker Hub
```
docker login
```
### Push your image to Docker Hub
```
docker push fritzthecat9/dockertest_api:latest
```
### Pull image on raspberry pi:
```
docker pull fritzthecat9/dockertest_api:latest
docker images
```
### Run on raspberry pi:
```
docker pull fritzthecat9/dockertest_api:latest
docker run -d -p 5000:5000 -p 5001:5001 -e ASPNETCORE_URLS="https://+:5001;http://+:5000" -e ASPNETCORE_HTTP_PORTS=5000 -e ASPNETCORE_HTTPS_PORT=5001 -e ASPNETCORE_ENVIRONMENT=Development -e ASPNETCORE_Kestrel__Certificates__Default__Password=password -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v "$HOME/.aspnet/https:/https/" fritzthecat9/dockertest_api:latest
```
### Remove container
```
docker rm container_name_or_id
```
### Remove image
```
docker rmi image_name_or_id
```
### 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
```
### Fetch docker api
```
curl http://localhost:5000/weatherforecast
curl https://localhost:5001/weatherforecast
-k - ignore certificate check
curl -k https://localhost:5001/weatherforecast
```
### Start and stop docker container
```
docker stop container_id
docker start container_id
```