From ffc2df6a41ce710071f4370898e57afa61615861 Mon Sep 17 00:00:00 2001 From: shm <41867+shm@users.noreply.github.com> Date: Thu, 16 Nov 2017 13:37:19 +0100 Subject: [PATCH] Add instructions to run app as Docker container (#68) --- .dockerignore | 2 ++ Dockerfile | 15 +++++++++++++++ README.md | 35 +++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..93f1361 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ab2607f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM node:9 + +WORKDIR /app + +RUN npm install -g contentful-cli + +COPY package.json . +RUN npm install + +COPY . . + +USER node +EXPOSE 3000 + +CMD ["npm", "run", "start:dev"] diff --git a/README.md b/README.md index 8ea146d..19e1072 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ To start the express server, run the following npm run start:dev ``` -Open [http://localhost:3000](http://localhost:3000) and take a look around. +Open [http://localhost:3000](http://localhost:3000) and take a look around. ## Steps for read and write access (recommended) @@ -72,7 +72,7 @@ Step 4: Seed the new space with the content model. Replace the `SPACE_ID` with t ``` contentful space seed -s '' -t the-example-app ``` -Step 5: Head to the Contentful web app's API section and grab `SPACE_ID`, `DELIVERY_ACCESS_TOKEN`, `PREVIEW_ACCESS_TOKEN`. +Step 5: Head to the Contentful web app's API section and grab `SPACE_ID`, `DELIVERY_ACCESS_TOKEN`, `PREVIEW_ACCESS_TOKEN`. Step 6: Open `variables.env` and inject your credentials so it looks like this @@ -97,3 +97,34 @@ You can also deploy this app to Heroku: [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) + +## Use Docker +You can also run this app as a Docker container: + +Step 1: Clone the repo + +```bash +git clone https://github.com/contentful/the-example-app.nodejs.git +``` + +Step 2: Build the Docker image + +```bash +docker build -t the-example-app.nodejs . +``` + +Step 3: Run the Docker container locally: + +```bash +docker run -p 3000:3000 -d the-example-app.nodejs +``` + +If you created your own Contentful space, you can use it by overriding the following environment variables: + +```bash +docker run -p 3000:3000 \ + -e CONTENTFUL_SPACE_ID= \ + -e CONTENTFUL_DELIVERY_TOKEN= \ + -e CONTENTFUL_PREVIEW_TOKEN= \ + -d the-example-app.nodejs +```