Skip to content

Commit ba2e176

Browse files
committed
docker instructions added
1 parent 5a3d412 commit ba2e176

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

CacheSample.WebApi/Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
1+
FROM centos:7 AS base
2+
3+
# Add Microsoft package repository and install ASP.NET Core
4+
RUN rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm \
5+
&& yum install -y aspnetcore-runtime-6.0
6+
7+
# Ensure we listen on any IP Address
8+
ENV DOTNET_URLS=http://+:3000
29

3-
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
410
WORKDIR /app
5-
EXPOSE 80
6-
EXPOSE 443
711

12+
# ... remainder of dockerfile as before
813
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
914
WORKDIR /src
1015
COPY ["CacheSample.WebApi/CacheSample.WebApi.csproj", "CacheSample.WebApi/"]

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# ASP.NET Core (.NET 6) Web API with cache
22

3+
To run this project from Docker
4+
5+
```sh
6+
$> docker build -t aspnet-core-net-6-api-cache -f ./CacheSample.WebApi/Dockerfile .
7+
$> docker create --name aspnet-core-net-6-api-cache-core aspnet-core-net-6-api-cache
8+
$> docker start aspnet-core-net-6-api-cache-core
9+
$> docker run --rm -p 3000:3000 aspnet-core-net-6-api-cache
10+
```
11+
12+
Solution sample to (port is already allocated)
13+
```
14+
Bind for 0.0.0.0:3000 failed: port is already allocated.
15+
16+
$> docker ps
17+
18+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19+
69e65c95dfaf aspnet-core-net-6-api-cache "dotnet CacheSample.…" 35 seconds ago Up 29 seconds aspnet-core-net-6-api-cache-core
20+
21+
$> docker stop 69e65c95dfaf
22+
23+
$> docker ps
24+
25+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
26+
27+
$> docker run --rm -p 3000:3000 aspnet-core-net-6-api-cache
28+
info: Microsoft.Hosting.Lifetime[14]
29+
Now listening on: http://[::]:3000
30+
info: Microsoft.Hosting.Lifetime[0]
31+
Application started. Press Ctrl+C to shut down.
32+
info: Microsoft.Hosting.Lifetime[0]
33+
Hosting environment: Production
34+
info: Microsoft.Hosting.Lifetime[0]
35+
Content root path: /app/
36+
```
37+
338
#### Using Memory
439
![image](https://user-images.githubusercontent.com/22874642/177662412-5d5e270c-09bf-4024-9a21-4df086c20e8b.png)
540

run.cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docker build -t aspnet-core-net-6-api-cache -f ./CacheSample.WebApi/Dockerfile .
2+
docker create --name aspnet-core-net-6-api-cache-core aspnet-core-net-6-api-cache
3+
docker start aspnet-core-net-6-api-cache-core
4+
docker run --rm -p 3000:3000 aspnet-core-net-6-api-cache

run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docker build -t aspnet-core-net-6-api-cache -f ./CacheSample.WebApi/Dockerfile .
2+
docker create --name aspnet-core-net-6-api-cache-core aspnet-core-net-6-api-cache
3+
docker start aspnet-core-net-6-api-cache-core
4+
docker run --rm -p 3000:3000 aspnet-core-net-6-api-cache

0 commit comments

Comments
 (0)