https://github.com/arnab-developer/basicdockercommands
Basic docker commands
https://github.com/arnab-developer/basicdockercommands
Last synced: 5 months ago
JSON representation
Basic docker commands
- Host: GitHub
- URL: https://github.com/arnab-developer/basicdockercommands
- Owner: Arnab-Developer
- License: mit
- Created: 2021-11-02T08:37:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-02T09:48:54.000Z (over 4 years ago)
- Last Synced: 2025-06-13T05:03:40.129Z (about 1 year ago)
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Basic docker commands
This is a document for basic docker commands. You need .NET 5 SDK and docker desktop installed in
your machine to follow the below steps.
## Create a .NET web api
Open terminal and execute the below commands to create a new .NET web api.
```
cd c:\
mkdir Api1
cd Api1
dotnet new webapi
dotnet run
```
Open a web browser and test the api with `http://localhost:5000/weatherforecast`.
Next publish the api in a separate folder.
```
cd c:\
mkdir Api1Publish
cd Api1Publish
mkdir publish
cd..
cd Api1
dotnet publish -c Release -o ../Api1Publish/publish
cd..
cd Api1Publish\publish
dotnet Api1.dll
```
Open a web browser and test the api with `http://localhost:5000/weatherforecast`.
## Create docker container
Create a `Dockerfile` inside `Api1Publish` folder (not inside the `publish` folder).

Write the below code inside that.
```
FROM mcr.microsoft.com/dotnet/aspnet:5.0
COPY publish/ ./app
WORKDIR /app
ENTRYPOINT ["dotnet", "Api1.dll"]
```
Create docker image.
```
cd c:\
cd Api1Publish
docker build -t api1:1.0.0 .
```
Create container from that image.
```
docker create --name c1 -p 80:80 api1:1.0.0
docker start c1
```
Open a web browser and test the api with `http://localhost:80/weatherforecast`.
## Clean up
```
docker rm c1
docker rmi api1:1.0.0
```
Delete the `Api1` and `Api1Publish` folders.