preparing docker

This commit is contained in:
Dobromir Popov
2021-07-29 18:59:49 +03:00
parent 8921fbd5ac
commit b4b6e7f538
7 changed files with 45 additions and 5 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
node_modules
npm-debug.log
docs
mysql.txt
test.js
mysql

15
Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM node:8
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD npm start
EXPOSE 8055
#
FROM mysql
ENV MYSQL_DATABASE iot
ENV MYSQL_ROOT_PASSWORD mitko2021
COPY schema.sql /docker-entrypoint-initdb.d/

18
docker-compose.yml Normal file
View File

@@ -0,0 +1,18 @@
version: '3.3'
services:
node-app:
build: .
environment:
- DATABASE_HOST=db
depends_on:
- db
restart: always
ports:
- 8055:8055
db:
build: ./mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: mitko2021
MYSQL_DATABASE: iot

View File

@@ -4,7 +4,8 @@
"description": " test api for IOT devices", "description": " test api for IOT devices",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "dev": "nodemon dht.js",
"start": "node dht.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -12,10 +12,10 @@ const config = require(__dirname + '/../../config/config.json')[env];
var pool = mysql.createPool({ var pool = mysql.createPool({
connectionLimit : 20, connectionLimit : 20,
host : config.host, host : process.env.DATABASE_HOST || config.host || '127.0.0.1',
user : config.username, user : process.env.DATABASE_USER || config.username,
password : config.password, password : process.env.DATABASE_PASS || config.password,
database : config.database database : process.env.DATABASE_DB || config.database
}); });
// var con = mysql.createConnection({ // var con = mysql.createConnection({
// host : 'localhost', // host : 'localhost',