|
@@ -75,7 +75,7 @@ docker run -p 5432:5432 \
|
|
|
|
|
|
```bash
|
|
|
# Without the -U, PG will try to use undeclared used root.
|
|
|
-docker container exec -it psql -U postgres
|
|
|
+docker container exec -it voting-pg psql -U postgres
|
|
|
```
|
|
|
* In `psql` in the container, list databases, create table, list tables:
|
|
|
```postgresql
|
|
@@ -99,8 +99,8 @@ CREATE TABLE votes (
|
|
|
```
|
|
|
* Insert initial data
|
|
|
```postgresql
|
|
|
-INSERT INTO votes (id, number_of_votes, option_name) VALUES (1, 0, 'sandwiches');
|
|
|
-INSERT INTO votes (id, number_of_votes, option_name) VALUES (2, 0, 'tacos');
|
|
|
+INSERT INTO votes (id, number_of_votes, option_name) VALUES (1, 13, 'sandwiches');
|
|
|
+INSERT INTO votes (id, number_of_votes, option_name) VALUES (2, 21, 'tacos');
|
|
|
SELECT * FROM votes;
|
|
|
```
|
|
|
* Results:
|
|
@@ -111,3 +111,34 @@ SELECT * FROM votes;
|
|
|
2 | 0 | tacos
|
|
|
(2 rows)
|
|
|
```
|
|
|
+
|
|
|
+# Step 4: PG in Node app
|
|
|
+
|
|
|
+* To reach PG, the app needs to know the address. To get to it from inside the
|
|
|
+container where the app runs, look for the `gateway` value in the results of
|
|
|
+`docker bridge`:
|
|
|
+
|
|
|
+```
|
|
|
+[...snip...]
|
|
|
+ "IPAM": {
|
|
|
+ "Driver": "default",
|
|
|
+ "Options": null,
|
|
|
+ "Config": [
|
|
|
+ {
|
|
|
+ "Subnet": "172.17.0.0/16",
|
|
|
+ "Gateway": "172.17.0.1"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+[...snip...]
|
|
|
+```
|
|
|
+
|
|
|
+* We then know that the IP to use in `client.connect()` will be `172.17.0.1`, at
|
|
|
+ least in the current configuration. Will probably have to come from the outside
|
|
|
+ for more flexibility.
|
|
|
+* Posting data to update:
|
|
|
+```bash
|
|
|
+curl -d"yourVote=sandwiches" http://localhost:8888/vote
|
|
|
+curl -d"yourVote=tacos" http://localhost:8888/vote
|
|
|
+curl -d"yourVote=invalid" http://localhost:8888/vote
|
|
|
+```
|