In simple hello world app in Node.js the port forwarding seems not to be working. When I am inside container and I run curl, I get correct response. Anyway from the main os I get empty reply from server.
Command docker container exec -it vigorous_knuth curl 127.0.0.1:80
produces Hello World
Command curl 127.0.0.1:80
produces curl: (52) Empty reply from server
OS: MacOs 12.1
Docker: Docker version 20.10.12, build e91ed57
Dockerfile:
FROM node
WORKDIR /code
COPY . .
ENV PORT 80
EXPOSE $PORT
RUN npm install curl
CMD ["node", "app.js", "&"]
App:
const http = require('http');
const hostname = '127.0.0.1';
const port = 80;
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}/`);
});
Command:
docker run -p 80:80 site:0.0.16