Skip to content

Instantly share code, notes, and snippets.

@edm00se

edm00se/Dockerfile Secret

Last active Nov 17, 2017
Embed
What would you like to do?
sample basic docker-compose.yml

Docker Compose Getting Started

Built from the "getting started" guide on docs.docker.com: https://docs.docker.com/compose/gettingstarted/

Required

  1. Docker
  2. Docker Compose (should come with Docker CE for macOS and Windows, if you're using toolbox, install it)

Adapted

Adapted from the original docker compose getting started guide to use Node w/ the Express framework in place of python.

Create from Scratch

  1. Create Docker image, build Dockerfile
  2. Build the image, docker build -t web .
  3. Define services, port bindings, in docker-compose.yml
  4. Build and run w/ compose, docker-compose up (add -d for it to run 'detatched', in background)

* To remove the container(s) defined by the docker-compose.yml, run docker-compose rm from cwd.

Clone and Run

  1. git clone https://github.com/edm00se/simple-docker-compose-node-redis-demo.git
  2. cd simple-docker-compose-node-redis-demo
  3. docker-compose up (first time run will perform build, can force a fresh build with --build)
  4. (optional) observe magic via Kitematic

License

The MIT License (MIT).

const express = require('express');
const app = express();
const session = require('express-session');
const RedisStore = require('connect-redis')(session);
const options = {
host: 'redis',
port: 6379,
logErrors: true
};
app.use(
session({
store: new RedisStore(options),
secret: 'amazing stuff',
resave: true,
saveUninitialized: true
})
);
RedisStore['hits'] = 0;
app.get('/', (req, res) => {
RedisStore['hits']++;
const num = RedisStore['hits'];
res.send(`Hello World!<br><p>I have been loaded ${num} times.</p>`);
});
app.listen(3000, () => {
console.log('Example app listening on port 3000!');
});
version: '3.1'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
volumes:
- .:/app
depends_on:
- redis
redis:
image: redis:alpine
FROM node:alpine
RUN mkdir -p /code
COPY . /code
WORKDIR /code
RUN npm install
CMD ["npm", "start"]
{
"name": "simple-docker-compose-node-redis-demo",
"version": "1.0.0",
"description": "simple hello world, with a configured redis db in Docker compose",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:edm00se/simple-docker-compose-node-redis-demo.git"
},
"author": "Eric McCormick (https://github.com/edm00se)",
"license": "MIT",
"homepage": "https://github.com/edm00se/simple-docker-compose-node-redis-demo#readme",
"dependencies": {
"connect-redis": "3.3.0",
"express": "4.15.3",
"express-session": "1.15.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.