- A simple .NET API
- Created using
dotnet new webapi
- Dockerized
- Created using
- CI/CD pipeline (GitHub Actions) to build image and upload to Docker Hub
- Workflow created using GitHub Action's default template for creating a Docker container, then expanded
- .NET SDK (.NET 7.0 used here as of July 2023)
- Docker Desktop and a Docker Hub account
- Clone/fork project
- In root folder, open terminal and run:
dotnet run
- Check https://localhost:5010/weatherforecast
To build a Docker-image, in root folder, open terminal and run:
docker build -t <YOUR_DOCKER_USERNAME>/dotnet-api-template .
To run image, open terminal and run:
docker run --name dotnet-api-template -dp 5010:80 <YOUR_DOCKER_USERNAME>/dotnet-api-template
- Check https://localhost:5010/weatherforecast
The workflow is defined in docker-image.yml. It will run automatically on every push to this branch.
In you Docker Hub account, create an access token. Remember the value! You will need it when configuring the GitHub Actions workflow.
In GitHub, in the repository for your API, under Settings > Secrets and variables > Actions; create two new secrets:
DOCKERHUB_USERNAME
containing your Docker Hub usernameDOCKERHUB_TOKEN
containing the access token you created for you Docker Hub account
These values will be used in the automated workflow to build and push your image to <DOCKERHUB_USERNAME>/dotnet-api-tamplate:latest
- Make a change in the API and push the changes to your repository.
- In GitHub, in your repository for this project, monitor the build process under the Actions tab.
- When done, check your Docker Hub account under Repositories and you should see a new image of this API.