|
@@ -65,11 +65,11 @@ docker run -p 8888:8888 \
|
|
|
mkdir postgres
|
|
|
cd postgres
|
|
|
# edit Dockerfile
|
|
|
-docker build -t node-pg .
|
|
|
+docker build -t voting-pg .
|
|
|
docker run -p 5432:5432 \
|
|
|
--name voting-pg \
|
|
|
--rm \
|
|
|
- node-pg
|
|
|
+ voting-pg
|
|
|
```
|
|
|
* Enter the container with a PG client:
|
|
|
|
|
@@ -142,3 +142,46 @@ curl -d"yourVote=sandwiches" http://localhost:8888/vote
|
|
|
curl -d"yourVote=tacos" http://localhost:8888/vote
|
|
|
curl -d"yourVote=invalid" http://localhost:8888/vote
|
|
|
```
|
|
|
+
|
|
|
+Step 5: persistence
|
|
|
+
|
|
|
+* Initialize PG as described on the image page, by adding a SQL file to the
|
|
|
+ container from the host into the `docker-entrypoint-initdb.d/` directory.
|
|
|
+
|
|
|
+ COPY seed.sql /docker-entrypoint-initdb.d/
|
|
|
+* Redefine the image-provided volume pointing to the PG data:
|
|
|
+
|
|
|
+ VOLUME /var/lib/postgresql/data
|
|
|
+* Rebuild container
|
|
|
+
|
|
|
+ cd postgres
|
|
|
+ docker container build -t voting-pg .
|
|
|
+* Run it. Beware: we can't have a `.gitkeep` in the `postgres/data` directory, which will
|
|
|
+ prevent PG from starting in that directory. But if we don't have it, the
|
|
|
+ directory will have to be created, because git won't save it.
|
|
|
+
|
|
|
+```bash
|
|
|
+cd postgres
|
|
|
+if [ ! -d data ]; then mkdir data fi
|
|
|
+docker container run \
|
|
|
+ --name voting-pg \
|
|
|
+ -p 9000:5432 \
|
|
|
+ -v $PWD/data:/var/lig/postgresql/data \
|
|
|
+ --rm -d \
|
|
|
+ voting-pg
|
|
|
+
|
|
|
+```
|
|
|
+* Run the app
|
|
|
+```bash
|
|
|
+cd node
|
|
|
+docker container run \
|
|
|
+ --name voting-node \
|
|
|
+ -p 8888:8888 \
|
|
|
+ -v $PWD/src:/usr/src/app/src \
|
|
|
+ --rm -d \
|
|
|
+ voting-node
|
|
|
+```
|
|
|
+* When stopping the PG container, the node app will crash and not restart.
|
|
|
+ Just touch the `server.js` file and `nodemon` in the node container will
|
|
|
+ restart it. This is only good for a development workflow: a production version
|
|
|
+ should handle disconnects.
|