4

If I launch a Docker container by first creating the image and then running it (docker build --rm -t myApp + docker run -p 80:80 -P -d myApp), everything works fine.

But, when I do the same with Docker-compose and access to localhost, the browser returns me a ERR_EMPTY_RESPONSE error (not the typical: "Connection refused").

Where am I wrong?

Docker-compose.yml:

version: '2'
services:
 myApp:
  build: myApp
  ports:
   - "80:8000"

/myApp/Dockerfile:

FROM fedora-nodeJS
ADD app.js /
EXPOSE 8000
CMD node app

/myApp/app.js:

var http  = require('http');

var PORT  = 8000;
var ADDR  = '0.0.0.0';

http.createServer(function(req, res) {
    res.writeHead(301, { Location: 'http://stackoverflow.com' });
    res.end();
}).listen(PORT,ADDR);

:: I know it makes no sense at all launch just one container with Docker-compose, but I had the same ERR_EMPTY_RESPONSE error when trying to launch several containers, so I ended up with this ridiculous scenario trying to understand whats failing.

2 Answers 2

5

In the command ,I can see

docker run -p 80:80 -P -d myApp

that you are exposing internal port 80 ,but in

docker-compose.yml

you are exposing internal port 8000

ports:
   - "80:8000"

Is that a typo ? Which port you actually want to expose for your app?

Sign up to request clarification or add additional context in comments.

Comments

2

As @emme pointed out, it is probably a typo in your case.

For anyone having the same problem but are 100% positive that their port configuration is correct, it might be a problem with your antivirus. My company had ESET endpoint Antivirus installed on my mac and by default the antivirus blocks access to localhost:80. While the server can be bound to port 80, no client connection to this server would work while the "Enable HTTP checking" (under "Web access protection") is activated.

Sounds like a stupid answer but I lost an afternoon figuring out why docker run -p 80:80 -P -d myApp would not work while docker run -p 81:80 -P -d myApp would.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.