Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"presets": [
"env"
]
}
MYSQL_ROOT_PASSWORD=123456
MYSQL_DATABASE=database
version: '3'
services:
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker.exposedbydefault=false # Enables the web UI and tells Træfik to listen to docker, without exposing by default
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
db:
image: mysql:5
restart: always
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
redis:
image: redis:alpine
app:
build:
dockerfile: Dockerfile-dev
context: .
command: npm run dev
volumes:
- "./src:/home/node/app/src"
environment:
- DB_HOST=db
- DB_NAME=${MYSQL_DATABASE}
- DB_USER=root
- DB_PASSWORD=${MYSQL_ROOT_PASSWORD}
- REDIS_HOST=redis
labels:
- "traefik.enable=true"
- "traefik.frontend.rule=Host:app.test.localhost.tv"
depends_on:
- db
- redis
###############################################################################
# Step 1 : Builder image
#
FROM node:9-alpine AS builder
# Define working directory and copy source
WORKDIR /home/node/app
COPY . .
# Install dependencies and build whatever you have to build
# (babel, grunt, webpack, etc.)
RUN npm install && npm run build
###############################################################################
# Step 2 : Run image
#
FROM node:9-alpine
ENV NODE_ENV=production
WORKDIR /home/node/app
# Install deps for production only
COPY ./package* ./
RUN npm install && \
npm cache clean --force
# Copy builded source from the upper builder stage
COPY --from=builder /home/node/app/build ./build
# Expose ports (for orchestrators and dynamic reverse proxies)
EXPOSE 3000
# Start the app
CMD npm start
FROM node:9-alpine
WORKDIR /home/node/app
# Install deps
COPY ./package* ./
RUN npm install && \
npm cache clean --force
COPY . .
# Expose ports (for orchestrators and dynamic reverse proxies)
EXPOSE 3000
# Start the app
CMD npm start
import express from 'express'
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
{
"name": "Docker-node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rm -rf build && mkdir build",
"build-babel": "babel -d ./build ./src -s",
"build": "npm run clean && npm run build-babel",
"start": "node ./build/index.js",
"dev": "babel-node src/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0"
},
"dependencies": {
"express": "^4.16.3"
}
}
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.