Skip to content

Commit

Permalink
Minor tweaks to lab 1 (#18)
Browse files Browse the repository at this point in the history
* Minor tweaks to lab 1
- Added docker compose instructions
- Added images for how to find the random port for pgadmin
- Fix localhost to host.docker.internal

* Update labs/1-Create-Catalog-API/README.md

Co-authored-by: Damian Edwards <[email protected]>

---------

Co-authored-by: Damian Edwards <[email protected]>
  • Loading branch information
davidfowl and DamianEdwards authored Feb 11, 2024
1 parent 3c0f1eb commit 33af23c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions labs/1-Create-Catalog-API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ A database has already been defined to store the product catalog for eShop, alon

In order to successfully run the the `Catalog.Data.Manager` application and see the database be created, a PostgreSQL database server is required. The project is pre-configured to connect to a local server using *trust* authentication in its `appsettings.Development.json` file. Docker is a simple way to run instances of databases for development.

We're going to run 2 docker container:, the PostgreSQL container, and [pgAdmin](https://www.pgadmin.org/). This will make it easy to inspect the database using a visual tool:

### Docker CLI

postgres

```
docker run --name postgres-dev -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 -d postgres
```

pgAdmin

```
docker run --name pgadmin-dev -e PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED=False -e PGADMIN_CONFIG_SERVER_MODE=False -e [email protected] -e PGADMIN_DEFAULT_PASSWORD=admin -p 0:80 -d dpage/pgadmin4
```

### Docker Desktop

1. Using Docker, create a container to host the PostgreSQL server with the following details:
- Name: `postgres-dev`
- Image: `postgres:latest`
Expand All @@ -23,7 +41,7 @@ In order to successfully run the the `Catalog.Data.Manager` application and see
- `POSTGRES_HOST_AUTH_METHOD` : `trust`

![Creating a container for PostgreSQL in Docker Desktop](./img/docker-postgres-dev.png)
1. Create another container to host an instance of [pgAdmin](https://www.pgadmin.org/). This will make it easy to inspect the database using a visual tool:
1. Create another container to host an instance of [pgAdmin](https://www.pgadmin.org/):
- Name: `pgadmin-dev`
- Image: `dpage/pgadmin4:latest`
- Ports: `0` (random)
Expand All @@ -43,7 +61,21 @@ In order to successfully run the the `Catalog.Data.Manager` application and see
![Logs and health-check endpoint of the Catalog.Data.Manager project showing the database initialization status](./img/catalog.data.manager-logs-and-health.png)

1. Stop the application and try launching it again and seeing the output of the `/health` endpoint return `Degraded` while the database initialization is still in progress.
1. Open the pgAdmin UI in another browser tab (find the host port assigned to the container's endpoint on port 80 in the Docker UI) and add the local PostgreSQL server instance by right-clicking on the **Servers** node in the tree-view and selecting **Register > Server** (use `localhost` in the **Connection** tab).
1. Find the port assigned to the pgAdmin container.

**Docker CLI**

```
docker ps
```

![Image of the docker CLI showing the port for pgAdmin](./img/find-docker-endpoint.png)

**Docker Desktop**

![Image of docker desktop UI showing the port for pgAdmin](./img/find-docker-endpoint-ui.png)

1. Open the pgAdmin UI in another browser tab and add the local PostgreSQL server instance by right-clicking on the **Servers** node in the tree-view and selecting **Register > Server** (use `host.docker.internal` in the **Connection** tab).
1. Expand the tree-view nodes under the server node you registered to see the that the tables representing the Entity Framework Core model have been created.

![pgAdmin UI showing the created tables](./img/pgadmin-postgres-dev.png)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 33af23c

Please sign in to comment.