Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. Hierarchy Folder
  2. test_dock4
  3. - db
  4. - web
  5. - node_modules
  6. - Dockerfile
  7. - index.js
  8. - package-lock.json
  9. - package.json
  10. - docker-compose.yml
  11.  
  12. //=================================
  13. Dockerfile
  14. FROM node:8.12.0
  15. # Create app directory
  16. RUN mkdir /webapp
  17. WORKDIR /webapp
  18.  
  19. # Install app dependencies
  20. COPY package.json /webapp
  21. RUN npm install
  22.  
  23. # Bundle app source
  24. COPY . /webapp
  25.  
  26. EXPOSE 8080
  27.  
  28. CMD ["node", "index.js"]
  29.  
  30. //=================================
  31. docker-compose.yml
  32. version: '2'
  33. services:
  34. web:
  35. container_name: web
  36. build: ./web/
  37. links:
  38. - db
  39. environment:
  40. - DATABASE_URL=postgres://api:123@db:5432/new_databases
  41. command: node index.js
  42. ports:
  43. - "8080:8080"
  44. volumes:
  45. - ./web:/webapp
  46. db:
  47. image: postgres
  48. container_name: db
  49. ports:
  50. - "5432:5432"
  51. environment:
  52. - POSTGRES_USER=api
  53. - POSTGRES_PASSWORD=123
  54. - POSTGRES_DATABASE=new_databases
  55.  
  56. //=================================
  57. index.js
  58. const express = require('express');
  59. const app = express();
  60.  
  61. const pg = require('pg');
  62. const PORT = 8080;
  63.  
  64. app.get('/', (req, res) => {
  65. res.status(200).json({msg: 'Testing Ok Bos'})
  66. });
  67.  
  68. app.listen(PORT, () => {
  69. console.log(`Server is listening on port ${PORT}`)
  70. });
  71.  
  72. //=================================
  73. Error:
  74. web | Error: Cannot find module '/webapp/index.js'
  75. web | at Function.Module._resolveFilename (module.js:548:15)
  76. web | at Function.Module._load (module.js:475:25)
  77. web | at Function.Module.runMain (module.js:694:10)
  78. web | at startup (bootstrap_node.js:204:16)
  79. web | at bootstrap_node.js:625:3
  80. web exited with code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement