I'm trying to make it work nodejs with docker-compose and volumes, I want to edit my code, that's why I should use volumes.
when I do not put volumes in the docker-compose.yml file, it work!. But with volumes no work.
Any idea?
This is my docker-compose.yml:
version: "3.2"
services:
node:
container_name: node_app
build:
context: ./
dockerfile: dockerfiles/Dockerfile
user: "node"
environment:
- NODE_ENV=production
volumes:
- .:/home/app
ports:
- "3000:3000"
This is my Dockerfile:
FROM node:carbon-stretch
WORKDIR /home/app
COPY package*.json ./
RUN npm i express -S
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
This is my package.json:
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <[email protected]>",
"main": "server.js",
"scripts": {
"start": "node server.js"
}
}
This is my server.js:
'use strict'
const express = require('express')
// Constants
const PORT = 3000
const HOST = '0.0.0.0'
// App
const app = express()
app.get('/', (req, res) => {
res.send('Hello world\n')
});
app.listen(PORT, HOST)
console.log(`Running on http://${HOST}:${PORT}`)
Thanks!