Skip to content

Commit e07aa6b

Browse files
Updated docker-compose and readme
1 parent cdcee21 commit e07aa6b

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
44

55
WORKDIR /app
66

7-
#EXPOSE 4000
7+
EXPOSE 4000
88
EXPOSE 4001
99
ENV ASPNETCORE_URLS=https://*:4000
1010
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build

Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void Main(string[] args)
6565
app.UseSwaggerUI();
6666
}
6767

68-
//app.UseHttpsRedirection();
68+
app.UseHttpsRedirection();
6969

7070
app.UseAuthorization();
7171
//ResourceConnector.GetGraphForResource("08ac06ea-4005-4e31-ae69-7ffc0447b332");

README.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,69 @@
11
# Repository
22

33
## Docker
4-
This project supports docker runtime environment.
4+
This project supports docker runtime environment, for which you will need to download docker from here: https://www.docker.com/products/docker-desktop/.
55

6-
To build the docker image run, download docker from https://www.docker.com/products/docker-desktop/.
6+
For this project, be aware that express listens on a specfic port (can be found in /API/Endpoints), which must be the same port that is used in the docker file.
7+
8+
Open a terminal and navigate to the root of the project.
9+
10+
## Docker network
11+
12+
If you run other services like a repository or service registry through docker locally, you will also need to setup a network. This creates a connection between local docker containers which is essential for establishing a connection.
13+
14+
If you want to run the project(s) with docker compose, the network needs to be created before running the compose file.
15+
16+
To create a docker network run below the commands below in a terminal:
17+
18+
```
19+
docker network create -d bridge data
20+
```
21+
22+
## Docker Compose
23+
It is recommended to use this approach to run the application. To run this project using docker-compose you need to follow the steps below:
24+
25+
Build the docker image:
26+
```
27+
docker-compose build
28+
```
29+
Run the docker image:
30+
```
31+
docker-compose up
32+
```
33+
Stop the docker image:
34+
```
35+
docker-compose down
36+
```
37+
38+
## Dockerfile
39+
Alternatively you can build the image directly from the Dockerfile by running the following commands from the root of the project:
40+
41+
```
42+
docker build -t Repository .
43+
docker run -d -p 4001:4001 -p 4000:4000 --name Repository dockerrepository:latest
44+
```
45+
46+
When running in docker, localhost and 127.0.0.1 will resolve to the container. If you want to access the outside host (e.g. your machine), you can add an entry to the container's /etc/hosts file. You can read more details on this here: https://www.howtogeek.com/devops/how-to-connect-to-localhost-within-a-docker-container/
47+
This will make localhost available as your destination when requesting from your host-unit e.g. from postman or the browser, not between containers.
48+
49+
To access the outside host, write the following docker run command instead of the one written above:
50+
```
51+
docker run -d -p 4001:4001 -p 4000:4000 --add-host host.docker.internal:host-gateway --name Repository dockerrepository:latest
52+
```
53+
54+
Here the value "host.docker.internal" maps to the container's host gateway, which matches the real localhost value. This name can be replaced with your own string.
55+
56+
To establish connections between containers, add a reference to the network by adding the below to your docker run:
57+
58+
```
59+
--network=data
60+
```
61+
62+
The full run command we recommend for local development:
63+
64+
```
65+
docker run -d -p 4001:4001 -p 4000:4000 --add-host host.docker.internal:host-gateway --network=data --name Repository dockerrepository:latest
66+
```
767

868
To establish a secure connection on a development environment, a certificate is necessary. Run the follow commands.
969

docker-compose.yaml

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
version: "3.7"
22

33
services:
4-
Reposistory:
4+
reposistory:
5+
container_name: reposistory
56
image: dockerrepository:latest
67
build: .
7-
#dockerfile: ./Dockerfile
88
ports:
99
- "4000:4000"
1010
- "4001:4001"
1111
environment:
1212
- ASPNETCORE_ENVIRONMENT=Development
13-
- ASPNETCORE_URLS="https://+;http://+"
14-
- ASPNETCORE_HTTPS_PORT=4000
15-
- ASPNETCORE_Kestrel__Certificates__Default__Password=1234
16-
- ASPNETCORE_Kestrel__Certificates__Default__Path=/https/Repository.pfx
17-
volumes:
18-
- ~/.aspnet/https:/https:ro
13+
- ASPNETCORE_URLS="http://+"
14+
networks:
15+
- data
16+
extra_hosts:
17+
- "localhost:host-gateway"

0 commit comments

Comments
 (0)