|
1 | 1 | # Repository
|
2 | 2 |
|
3 | 3 | ## 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/. |
5 | 5 |
|
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 | +``` |
7 | 67 |
|
8 | 68 | To establish a secure connection on a development environment, a certificate is necessary. Run the follow commands.
|
9 | 69 |
|
|
0 commit comments