I am running docker desktop for windows version 3.0.0 and am attempting to setup a basic hello world example using docker and docker-compose. when I run docker-compose up
the containers build fine and log the appropriate Server running at...
messages.
However when I navigate to localhost:3000
I would expect to see 'Hello World' and am instead seeing a browser error reading "This page isn’t working localhost didn’t send any data."
when I run the server.js file directly in node, I get "hello world" at localhost:3000
as expected.
Ideally I would be able to access all of my docker containers on local host ports 3000-3003. relevant files are below.
Each of my dockerfiles contain the following
FROM node:14
WORKDIR /usr/src/app
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "node", "server.js" ]
Below is the server.js file:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
My docker-compose file is below:
version: "3.9"
services:
analyze:
build: services/analyze/
volumes:
- ./services/analyze:/analyze
ports:
- "3000:3000"
extract:
build: services/extract/
volumes:
- ./services/extract:/extract
ports:
- "3001:3000"
search:
build: services/search/
volumes:
- ./services/search:/search
ports:
- "3002:3000"
reply:
build: services/reply/
volumes:
- ./services/reply:/reply
ports:
- "3003:3000"