오윤석

docker initialize

/app/config
/app/node/node_modules
\ No newline at end of file
version: "3"
services:
web:
image: nginx
container_name: nginx
ports:
- "8081:80"
networks:
mynet:
ipv4_address: 172.28.0.2
volumes:
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
- ./web:/var/www/html
restart: on-failure
links:
- app
app:
image: node
container_name: node
ports:
- "8082:80"
networks:
mynet:
ipv4_address: 172.28.0.3
working_dir: /app
volumes:
- ./node:/app
- ./config:/app/config
command: bash -c "npm install && node app.js"
environment:
- NODE_ENV=production
links:
- db
depends_on:
- db
restart: on-failure
db:
image: mariadb:10.2
container_name: mariadb10.2
ports:
- "33066:3306"
networks:
mynet:
ipv4_address: 172.28.0.4
volumes:
- mariadb:/var/lib/mysql
- ./config:/config
environment:
MYSQL_ROOT_PASSWORD_FILE: ./config/db_password.txt
MYSQL_DATABASE: maple
MYSQL_USER: maple
MYSQL_PASSWORD_FILE: ./config/db_password.txt
TZ: Asia/Seoul
command: --character_set_client=utf8 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --character-set-client-handshake=FALSE
restart: on-failure
volumes:
mariadb:
networks:
mynet:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
\ No newline at end of file
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/access.log.1;
error_log /var/log/nginx/error.log.1;
location /api {
proxy_pass http://172.28.0.3;
}
location / {
root /var/www/html;
index index.html;
}
}
\ No newline at end of file
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');
var fs = require('fs');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
var db;
fs.readFile('./config/db_password.txt', function(err, data) {
db = mysql.createConnection({
host: "172.28.0.4",
port: 3306,
user: "root",
password: data,
database: "mysql"
});
db.connect();
});
app.get('/query', function (req, res) {
db.query("SHOW DATABASES",
function(err, results, fields) {
if (err) throw err;
var string = JSON.stringify(results);
res.send(string);
}
);
});
var server = app.listen(80);
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"http": "0.0.1-security",
"mysql": "^2.18.1"
}
}
hello world
\ No newline at end of file